如何防止 NetLogo 补丁重叠?
How can I prevent NetLogo patches to overlap?
我有一个关于 NetLogo 的问题。
我想创建 N 个蓝色补丁,周围是灰色补丁(和一些海龟,但对于这个问题并不重要)。
这些补丁不应重叠,并且它们之间至少有 1 个黑色补丁。
但是,它们确实重叠。
我做错了什么?我该如何解决?
提前致谢!
patches-own []
turtles-own [need awareness mode]
to setup
clear-all
ask n-of N patches with [pcolor = black and all? neighbors [pcolor = black] and all? neighbors [all? neighbors [pcolor = black]]] [
set pcolor blue
ask neighbors [
set pcolor grey
]
]
ask n-of M patches with [pcolor != blue and pcolor != grey and not (any? neighbors with [pcolor = grey])] [
set pcolor red
sprout 1 [set color white]
]
reset-ticks
end
to go
end
你的代码的问题是Netlogo首先选择N个符合条件的随机补丁,将它们放入一个代理集中,然后让它们依次执行命令。如果所有条件仍然适用于最初选择的所有补丁,它不会在两者之间重新评估。
相反,我建议 repeat
和 one-of
以便在前一个补丁完成后选择每个新补丁。
repeat N [
ask one-of patches with [pcolor = black and all? neighbors [pcolor = black] and all? neighbors [all? neighbors [pcolor = black]]] [
set pcolor blue
ask neighbors [
set pcolor grey
]
]
]
我有一个关于 NetLogo 的问题。 我想创建 N 个蓝色补丁,周围是灰色补丁(和一些海龟,但对于这个问题并不重要)。 这些补丁不应重叠,并且它们之间至少有 1 个黑色补丁。 但是,它们确实重叠。
我做错了什么?我该如何解决?
提前致谢!
patches-own []
turtles-own [need awareness mode]
to setup
clear-all
ask n-of N patches with [pcolor = black and all? neighbors [pcolor = black] and all? neighbors [all? neighbors [pcolor = black]]] [
set pcolor blue
ask neighbors [
set pcolor grey
]
]
ask n-of M patches with [pcolor != blue and pcolor != grey and not (any? neighbors with [pcolor = grey])] [
set pcolor red
sprout 1 [set color white]
]
reset-ticks
end
to go
end
你的代码的问题是Netlogo首先选择N个符合条件的随机补丁,将它们放入一个代理集中,然后让它们依次执行命令。如果所有条件仍然适用于最初选择的所有补丁,它不会在两者之间重新评估。
相反,我建议 repeat
和 one-of
以便在前一个补丁完成后选择每个新补丁。
repeat N [
ask one-of patches with [pcolor = black and all? neighbors [pcolor = black] and all? neighbors [all? neighbors [pcolor = black]]] [
set pcolor blue
ask neighbors [
set pcolor grey
]
]
]