首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在偶数和奇数情况下每个补丁填充海龟的差异?

在偶数和奇数情况下每个补丁填充海龟的差异?
EN

Stack Overflow用户
提问于 2014-06-15 02:26:19
回答 2查看 309关注 0票数 2

我是netlogo的新手,在我的模型中,我试图让每个补丁都有一只海龟,这样所有的补丁都会填满一只海龟,而不是相互重叠。该模型部分的代码为

代码语言:javascript
复制
  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上。

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2014-06-15 02:30:41

实际上,有一个原语可以在给定的补丁上创建一只乌龟:sprout。因此,ask patches [ sprout 1 ]会在每个补丁上创建一只乌龟。

票数 2
EN

Stack Overflow用户

发布于 2014-06-15 03:15:49

Bryan的答案很可能是正确的,这里:如果你的主要需求是每个补丁有一个海龟,那么sprout是可行的。

更多的评论:

  • 在您向我们展示的屏幕截图中,您可以分别控制您的“体积”和粒子数量,因此对于您想要的粒子数量来说,您的容器总是有可能太大或太小。如果你真的想在容器的大小和粒子的数量之间建立一对一的关系,你真的应该为both.
  • sprout提供一个单独的参数,它允许你向新创建的乌龟发出命令。如果你不希望它们是“彩虹色的”,你可以这样做:ask patches with [pcolor = black] [sprout 1 [set color blue]].
  • In你的原始代码,你设置你的乌龟的xcorycor ...然后立即移动它们。如果使用sprout,这一点就没有意义了,但是我想指出,这两行代码是unnecessary.

如果您仍然无法使用sprout,我建议您单独问一个问题,并向我们展示您尝试过的内容。我们也许能帮到你。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24222939

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档