how to move the turtles together free neighbors without other turtles occupy them

我只是一个虾纸丫 提交于 2019-12-11 12:59:04

问题


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:

  1. look 3 patches ahead at distance 2
  2. if any? turtles-on this
  3. 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)
  4. fd 1

来源:https://stackoverflow.com/questions/24514369/how-to-move-the-turtles-together-free-neighbors-without-other-turtles-occupy-the

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!