让海龟随机出现在特定的补丁上

Making turtles appear randomly on specific patches

我使用 GIS 创建了一个城市的路线图。我希望乌龟在设置过程中随机出现在道路的任何补丁上。我该怎么做?

使用 "n-of"、"with" 和 "sprout" 命令即可完成工作。

to world                                           ## This block will make the colors, 
                                                   ##you won't want to use this but it made the example reproducible
 ask patches [set pcolor random 50]
end

to make_turtles
  let Q 5                                          ##set this to the number of patches you want to spawn a turtle
  ask n-of Q patches with [pcolor = 30] [sprout 1] ##tells Q number of random of patches with 
                                                   ##the desired character (in this case pcolor = 30)
                                                   ## to sprout 1 turtle
end

您可以将 [XXX] 位更改为

with [ROAD=TRUE]

如果你想用自有变量放一个可重现的例子,它会更容易给你一个更有用的答案

修补[道路?]

turtles-own [home-patch]

设置

setup-drivers

结束

到setup-drivers
create-drivers number-of-cars [
设置 home-patch one-of 个带有 [ 道路? = 真]
设置形状 "airplane"
设置颜色 25
设置尺寸 8
move-tohome-patch
]
结束