我是netlogo的新手,在我的模型中,我试图让每个补丁都有一只海龟,这样所有的补丁都会填满一只海龟,而不是相互重叠。该模型部分的代码为
to solid
set color blue
set xcor random sqrt number-of-particles - number-of-particles / 2
set ycor random sqrt number-of-particles - number-of-particles / 2
ifelse any? patches with [pcolor = black and count turtles-here = 0]
[move-to one-of patches with [pcolor = black and count turtles-here = 0]]
[die]
end我一直在尝试使用不同的变量,但它适用于奇数"Volume“(每行中的补丁数量),但不适用于偶数。
(偶数编号的1) Link 1
(奇数编号的1) Link 2
我如何才能使它同时适用于奇数和偶数?谢谢!
这是我的完整设置代码。很抱歉在我的评论中发布了它们,这是我第一次在stackoverflow上。
to Setup-Container
ca
cro 4
[set color black
rt 45
fd Volume * sqrt 2 / 2
rt 135
pd
set pen-size 6
fd Volume
die
]
ask patches
[ifelse pxcor <= Volume / 2 and pxcor >= Volume / 2 * -1
and pycor <= Volume / 2 and pycor >= Volume / 2 * -1
[set pcolor black] [set pcolor black + 3]
]
end
; Creates a number of particles, which depends on the corresponding slider.
; Executes certain commands depending on the temperature slider.
to Setup-Particles
ask turtles
[die]
cro number-of-particles
ask turtles [
set shape "water"
if Temperature <= 0 ; freezing point is 0 degrees celsius.
[ice-cube]
if Temperature > 0 and Temperature < 100
[water]
if Temperature >= 100 ; boiling point is 100 degrees celsius.
[water-vapor]
]
end发布于 2014-06-15 02:30:41
实际上,有一个原语可以在给定的补丁上创建一只乌龟:sprout。因此,ask patches [ sprout 1 ]会在每个补丁上创建一只乌龟。
发布于 2014-06-15 03:15:49
Bryan的答案很可能是正确的,这里:如果你的主要需求是每个补丁有一个海龟,那么sprout是可行的。
更多的评论:
sprout提供一个单独的参数,它允许你向新创建的乌龟发出命令。如果你不希望它们是“彩虹色的”,你可以这样做:ask patches with [pcolor = black] [sprout 1 [set color blue]].xcor和ycor ...然后立即移动它们。如果使用sprout,这一点就没有意义了,但是我想指出,这两行代码是unnecessary.如果您仍然无法使用sprout,我建议您单独问一个问题,并向我们展示您尝试过的内容。我们也许能帮到你。
https://stackoverflow.com/questions/24222939
复制相似问题