Netlogo如何询问海龟等待其他海龟超过特定距离

Netlogo如何询问海龟等待其他海龟超过特定距离,netlogo,agent-based-modeling,Netlogo,Agent Based Modeling,我正在尝试用Netlogo编写代码,要求海龟们等待一定的时间(例如:2秒),如果他的邻居距离他不到一定的距离。当他和邻居之间的距离超过这个距离后,这只乌龟就可以开始移动了。以下是我的代码片段: 我的海龟初始设置: ;;send people back to where they come from ask turtles [ move-to one-of road with [not any? other turtles in-radius 4] ] 让海龟移动: to m

我正在尝试用Netlogo编写代码,要求海龟们等待一定的时间(例如:2秒),如果他的邻居距离他不到一定的距离。当他和邻居之间的距离超过这个距离后,这只乌龟就可以开始移动了。以下是我的代码片段:

我的海龟初始设置:

;;send people back to where they come from
  ask turtles [
    move-to one-of road with [not any? other turtles in-radius 4]
  ]
让海龟移动:

  to move
           face best-way-to goal
           ifelse patch-here != goal
            [ 
              ifelse how-close < 2
              [wait 2 fd 1]
              [fd 1]
            ]
            [stop]
    end

to-report keep-distance
   set close-turtles other turtles-on (patch-set patch-here neighbors4)
   ifelse any? close-turtles
       [set how-close distance min-one-of close-turtles [distance myself]]
       [set how-close 100] ;this means cannot find neighbours around this people
   report how-close
end
移动
面对目标的最佳方式
如果还有补丁在这里!=目标
[ 
否则,距离<2有多近
[等待2 fd 1]
[fd 1]
]
[停止]
结束
报告保持距离
让其他海龟靠近(贴片在此处设置贴片4)
还有别的吗?封闭海龟
[设置一只乌龟的最小距离[距离我自己]]
[设置接近100的距离];这意味着在这些人周围找不到邻居
报告距离有多近
结束

但这并没有给我想要的。有人知道如何在Netlogo中实现这一点吗?任何帮助都是非常感激的。谢谢

使用
wait
的问题是模型会暂停,因此其他海龟也不会移动,也无法离开。如果您只想让海龟在无人靠近时移动,请尝试替换:

to move
  face best-way-to goal
  ifelse patch-here != goal
  [ 
    ifelse how-close < 2
    [wait 2 fd 1]
    [fd 1]
  ]
  [stop]
end

也就是说,您不需要使用
ifelse
构造,您可以使用
if
,只需在条件合适时移动即可。

非常感谢您的回复。但是当我把你的代码粘贴到Netlogo上时,海龟们就不再转发了。我想这是因为它们之间的距离最初小于2,所以它们不会走路?你知道这件事吗?谢谢如果以感谢的价值开始多么接近!我已经修改了我的问题并添加了海龟设置代码。那么海龟理论上应该在半径4没有人的情况下发芽?但是我运行的代码仍然没有移动。这有助于解释我的问题吗?(1)请把这变成一个新问题。(2) 执行此操作时,请包括调用keep distance过程的代码,以及turtle或全局变量的接近程度
to move
  face best-way-to goal
  if patch-here != goal and how-close >= 2
  [ forward 1
  ]
end