我对 Netlogo 和 stackoverflow 都是新手,但是您的其他帖子已经对我有很大帮助。
我目前正在尝试编写一个模型,其中代理随机游荡一个空间并让他们在遇到时停下来。“相遇”在这里的意思是“互相擦肩而过in-radius 2
”。他们应该face
互相,等待 2 个滴答声,然后继续移动,直到找到下一个代理。
我试图在计时器上使用 NzHelen 的问题,但并没有真正成功。
到目前为止,我设法让他们面对面。我无法将tick
-command 放在代码中的正确位置。(编辑:这通过取出wait
-command 解决了,感谢 Seth。--> 我不希望所有的海龟都停止移动,而只希望那些正在相遇的海龟)。我正在努力的另一件事是他们相遇的某种视觉表示,例如当他们相遇时让补丁闪烁,或者当他们相遇时在他们周围出现一个圆圈。使用wait
-command,一切都会再次停止,这是我想要阻止的。
到目前为止的代码下方。
to go
tick
ask turtles
[
wander
find-neighbourhood
]
ask turtles with [found-neighbour = "yes"]
[
face-each-other
]
ask turtles with [found-neighbour = "no" or found-neighbour = "unknown"]
[ wander ]
end
;-------
;Go commands
to wander
right random 50
left random 50
forward 1
end
to find-neighbourhood
set neighbourhood other turtles in-radius 2
if neighbourhood != nobody [wander]
find-nearest-neighbour
end
to find-nearest-neighbour
set nearest-neighbour one-of neighbourhood with-min [distance myself]
ifelse nearest-neighbour != nobody [set found-neighbour "yes"][set found-neighbour "no"]
end
to face-each-other ;;neighbour-procedure
face nearest-neighbour
set found-neighbour "no"
ask patch-here [ ;; patch-procedure
set pcolor red + 2
;wait 0.2
set pcolor grey + 2
]
if nearest-neighbour != nobody [wander]
rt 180
jump 2
ask nearest-neighbour
[
face myself
rt 180
jump 2
set found-neighbour "no"
]
end