Netlogo 如何让海龟在特定的时间内来回走动?

Netlogo 如何让海龟在特定的时间内来回走动?,netlogo,Netlogo,在开始时,我setxy确定海龟在补丁周围的位置,然后我希望它们移动到特定的位置。当滴答声过去时(就像4小时后,你应该搬到其他地方),我希望他们搬到另一个地方。这是我的密码 turtles-own [start-patch destination work-hour rest-hour] to setup clear-turtles reset-ticks create-turtles 50 ask turtles [ setxy random-xcor random

在开始时,我
setxy
确定海龟在补丁周围的位置,然后我希望它们移动到特定的位置。当滴答声过去时(就像4小时后,你应该搬到其他地方),我希望他们搬到另一个地方。这是我的密码

turtles-own [start-patch destination work-hour rest-hour]

to setup
  clear-turtles
  reset-ticks
  create-turtles 50
  ask turtles
  [
    setxy random-xcor random-ycor
    set start-patch one-of patches with [pcolor = pink]
    set work-hour 0
    set rest-hour 0
  ]
end


to go
  ask turtles [pick-patch]
  tick
end

to pick-patch
  set destination one-of patches with [pcolor = orange + 3]
  ifelse destination != nobody
  [
    travel
  ]
  [fd 0]
end

to travel
  if distance destination > 1
  [face destination fd random 4]
  if patch-here = destination
  [
    wander
    set work-hour work-hour + 1
  ]
  if (work-hour > 30 and distance start-patch > 1)
  [face start-patch fd random 4]
  if patch-here = start-patch
  [
    wander
    set rest-hour rest-hour + 1
  ]
end

to wander
  ifelse random 2 = 0 [rt random 60] [lt random 60]
end

一开始,海龟正朝着
目的地移动,它们在那里移动并停留了大约200次(我不知道为什么,因为我只编码了30次)。然后他们开始移动到另一个位置(即
开始修补程序
)。一旦它们到达
开始补丁
,它们就会消失并出现在
目标
位置

我如何修复代码,让它们像例行公事一样来回移动


提前谢谢。

您有几个基本的逻辑问题。(1) go过程调用“拾取修补程序”。所以目的地总是在变化。(2) 当您检查工作时间是否大于30小时时,您还可以检查距离。如果工作时间>30且距离<1,但实际上不在起始补丁上,会发生什么情况?你的代码忽略了那些海龟的存在。(3) 您从未将工作和休息时间重置为0

您需要进行一些逻辑调试。试着检查一下你的一只海龟,看看每个刻度上的变量,仔细想想代码要求海龟做什么,与你真正想要它做什么相比。或者将您的海龟数量减少到1,这样您就可以获得代码来告诉您以下语句发生了什么:

ask turtles
[ type "my location is: " print patch-here
  type " going to: " print destination
  type "worked for: " print work-hour
]