网标如何问海龟等到其他海龟超过特定距离



我正在尝试在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

但这并没有给我我想要的。有人知道如何在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

to move
face best-way-to goal
if patch-here != goal and how-close >= 2
[ forward 1
]
end

也就是说,您不需要ifelse结构,您可以使用if并且仅在条件适合移动时才简单地移动。

最新更新