问题
I want to move turtles with a "security distance" from other turtles, for example one patch. this is my code:
ask turtles [
let q neighbors with [
(not any? turtles-here) and (not any? other turtles-on neighbors)
]
if any? q [
face one-of q
move-to patch-ahead 1
]
]
if any? turtles-on neighbors [ ????? ]
the start condition is each turtles not have turtles-on neighbors. Also i wish turtles find a new patch to go if turtles-on q or any turtles-on q neighbors, but i have no idea..
i try also this:
to move
ask turtles [
set ahead patches at-points [[2 1] [2 0] [2 -1]]
set neighbors-e patch-at 1 0
ask turtles with [not any? turtles-on ahead] [
let d distance exit ;exit is patch "target"
if (distance [exit] of neighbors-e < d) [
fd 1
]
]
]
end
but it shows the error : A patch can't access a turtle variable without specifying which turtle. (refer to neighbors-e)
The idea is:
- look 3 patches ahead at distance 2
- if any? turtles-on this
- control if the distance of exit where you will go (neighbors-e) is lesser than actual position (to verify if direction to exit is correctly)
- fd 1
来源:https://stackoverflow.com/questions/24514369/how-to-move-the-turtles-together-free-neighbors-without-other-turtles-occupy-the