在偶数和奇数情况下,每个补丁的海龟数量的差异



我是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

我一直在用不同的变量尝试它,但它适用于奇数"体积"(每行补丁的数量),而不是偶数。

(偶数)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

实际上有一个原语,它只是在给定的补丁上创建一个海龟:sprout。因此,ask patches [ sprout 1 ]将在每个补丁上创建一只海龟。

Bryan的回答很可能是正确的:如果你的主要要求是在每个补丁中有一只海龟,那么sprout就是最好的选择。

更多注释:

  • 在你给我们看的截图中,你可以分别控制你的"体积"和粒子数量,所以你的容器总是有可能太大或太小而不能容纳你想要的粒子数量。

  • 如果你真的想要容器大小和粒子数量之间的一对一关系,你应该为两者都设置一个参数。
  • sprout允许您向新创建的海龟发出命令。如果你不想让它们变成彩虹色,你可以这样做:ask patches with [pcolor = black] [sprout 1 [set color blue]] .

  • 在您的原始代码中,您设置了海龟的xcorycor…然后立即移动它们。如果您使用sprout,这一点将没有意义,但我想指出这两行是不必要的。

如果你仍然对sprout有问题,我建议你问一个单独的问题,并向我们展示你的尝试。

最新更新