我希望我的海龟在一个滴答的时间内到达目标并再次回家(使用fd
)。当我一个接一个地执行go过程(“ go一次”)时,该模型运行良好。但是,执行为循环(不更改代码)是行不通的:乌龟不动;滴答计数器已更新。似乎功能已正确执行,但运动未可视化。感谢您的帮助!
to go
if ticks >= 365 [ stop ]
move
if not any? turtles with [ shape = "person" and movement-done? = false ]
[
tick
ask turtles with [ shape = "person" ] [
set movement-done? false
set reached? false
set at-home-again? false ]
]
end
to move
ask turtles with [ shape = "person" ]
[
if movement-done? = false
[
ifelse reached? = false
[
ifelse patch-here = target [ set reached? true set at-home-again? false ]
[
face target
fd 1
]
]
[
ifelse at-home-again? = false
[
ifelse patch-here = myhome [ show "patch-here = myhome" set at-home-again? true ]
[
face myhome
fd 1
]
]
[
set movement-done? true
]
]
]
]
end