我想改变龟的行为。
前6个蜱虫,海龟用觅食地图移动。 觅食后,海龟使用休息地图在6个蜱虫中休息。我尝试使用倒计时,但它失败了。
to go
move-turtles
tick
if ticks >= 4320
[stop]
end
to move-turtles
ask turtles
[
foraging
resting
]
end
to foraging
uphill food
if food >= [food] of one-of neighbors
[move-to one-of neighbors]
set count-down count-down - 1
set label count-down
set label-color red
if count-down = 0
[resting
set label "6"
reset-count-down
]
end
to resting
uphill rplace
if rplace >= [rplace] of one-of neighbors
[move-to one-of neighbors]
set count-down count-down - 1
set label count-down
set label-color blue
if count-down = 0
[foraging
set label "6"
reset-count-down
]
end
to reset-count-down
set count-down 6
end
答案 0 :(得分:0)
您需要添加一个乌龟属性来跟踪乌龟的状态。例如,您可以添加resting?
属性,当觅食倒数达到{{1}时,您设置为true
1}},并在休息倒计时达到0
时设置为false
。然后,您将调整此属性的行为(觅食或休息)。
顺便说一句,通常你应该用动词命名命令程序(这里是0
和forage
)。