Netlogo Sprouting turtles spaced at less than one patch

寵の児 提交于 2019-12-04 05:12:16

问题


I want to place turtles on each of the black patches(below Figure) such that there is no gap between turtles at all:

Code I use right now:

ask patches with [pcolor = black][sprout-dead-turtles wall-agents [set color red]]

This gives the following result:

But I want to place turtles in between each of the two patches as well. So that I can cover the showing black part.

Note: Changing the shape of turtles is no use to my purpose though it would cover the black area. My aim to create a replusion force field from these agents and gaps in between are loop holes from where agents may escape.[Somewhat similar to agents bouncing back on a wall].


回答1:


Here is a fun solution:

breed [ dead-turtles dead-turtle ]

to setup
  ca  
  ; draw the background:
  ask patches with [ abs pxcor != max-pxcor and abs pycor != max-pycor ] [ set pcolor grey ]
  ask patches with [ pycor = max-pycor and abs pxcor <= 1 ] [ set pcolor white ]
  set-default-shape dead-turtles "circle"

  ; sprout a first set of turtles:
  ask patches with [ pcolor = black ] [
    sprout-dead-turtles 1 [ set color red ]
  ]

  ; create temporary links between these, and use the
  ; links to place a new set of turtles in between:
  ask dead-turtles [
    create-links-with turtles-on neighbors4 
  ]
  ask links [
    let target end2
    ask end1 [
      hatch 1 [
        face target
        fd distance target / 2
      ]
    ]
    die ; remove the link
  ]
end

I'm not saying that it is the only possible solution, but it's simple enough, and it works. (World wrapping has to be turned off, though, which I assume is the case.)



来源:https://stackoverflow.com/questions/25221007/netlogo-sprouting-turtles-spaced-at-less-than-one-patch

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