问题
I am trying to create a number of groups of agents on the NetLogo world. I hope each of the groups is located at a specific area without overlap. As I can think of, the easies way to achieve this might be dividing the world into several parts first. Each part consists of a number of patches (say 100 + random 10, which I can set) and is colored with a unique color. Then ask the newly created turtles to move to patches with different colors. Could anybody tell me how to achieve this or give any suggestion, please? Thanks in advance.
回答1:
One strategy is to grow different regions. For example:
to grow-regions [ num-regions ]
let region-num 0
ask n-of num-regions patches [
set pcolor item region-num base-colors
set region-num region-num + 1
]
while [ any? patches with [ pcolor = black ] ] [
ask patches with [ pcolor != black ] [
ask neighbors with [ pcolor = black ] [ set pcolor [ pcolor ] of myself ]
]
]
end
Note that this can draw at most 14 different regions (since that's the number of base colors).
This results in regions like so:
Edit: Misread your comment. Obviously, this doesn't let you control the size of the regions, but the average size will be count patches / num-regions
.
来源:https://stackoverflow.com/questions/23698008/divide-netlogo-world-into-several-random-parts