NetLogo:计算海龟'补丁上的后代(通过萌芽功能?)

时间:2015-08-10 19:47:51

标签: netlogo

在我的NetLogo世界表面上,我想计算粉红色斑块上的海龟数量。接下来,我想要包括复制过程。更具体地说,我希望将这些斑块上的龟数乘以每只龟的数量(3),从而创造新的龟。后代应该具有父母的品质。

分步骤: 1.在粉红色斑块上创造100只乌龟(父母) 2.确定每个粉红色斑块的龟数(我希望将该模型合并为更大的斑块)并将其乘以3 - > 100个父母有300个后代 3.让父母死去,只留下后代 4.每粉红色贴片产生的龟数:300

似乎使用sprout足以在每个粉红色斑块上生产海龟。但是我不明白我怎样才能包含这个后代的创作?我知道我可以通过

计算每个补丁的数量
  

用[pcolor = pink]

显示[计数海龟 - 这里]补丁

但如何将这些信息包含在我的新龟(后代)创作中?以及如何"复制"他们父母的素质? (红色?)

我尝试将此处发布的答案合并但未成功:Sprouting turtles in NetLogo based on patch value

非常感谢,这是我的代码:

to setup
  clear-all
  setup-patches
  setup-turtles
  reset-ticks
end

; create diverse landscape
to setup-patches
  ask n-of 5 patches [ set pcolor pink ]
end

; create turtles on pink patches

to setup-turtles 
  ask patches with [pcolor = pink] [sprout 100 [ set color red ]]   
  ; ask patches with [pcolor = pink] [count turtles-here]
  ; show [count turtles-here] of patches with [pcolor = pink]        ; calculate number of turtles on every pink patch
  let patch-list [count turtles-here] of patches with [pcolor = pink] 
  let i 0
  foreach patch-list [
    ask ? [
      sprout item i patch-list
      set plabel count turtles-here
    ]
    set i i + 1
  ]
  reset-ticks
end

2 个答案:

答案 0 :(得分:3)

您正在寻找的原语是hatch。如果askhatch后代的父母,它会自动复制后代的所有父级属性:

to setup
  clear-all
  ask n-of 5 patches [ set pcolor pink ]

  ; create 100 parent turtles on pink patches
  ask patches with [ pcolor = pink ] [ sprout 100 ]

  ; show that each pink patch has 100 turtles on it (the parents)
  show [ count turtles-here ] of patches with [ pcolor = pink ]

  ; ask each parent to hatch 3 offsprings and then die
  ask turtles [
    hatch 3
    die
  ]

  ; show that each pink patch now has 300 turtles on it (the offsprings)
  show [ count turtles-here ] of patches with [ pcolor = pink ]

end

答案 1 :(得分:0)

轻松解决方案,合并

  

sprout count turtles- here

进入我的简单公式:

to setup
  clear-all
  setup-patches
  setup-turtles
  reset-ticks
end

to setup-patches
  ask n-of 5 patches [ set pcolor pink ]
end

to setup-turtles 
  ; create parents
  ask patches with [pcolor = pink] [sprout 100 [ set color red ]]  
  ; create offsprings (*3) and let parents die (- count turtles-here)
  ask patches with [pcolor = pink] 
    [sprout count turtles-here * 3 - count turtles-here [ set color red ]]
  ; show [count turtles-here] of patches with [pcolor = pink] 
  ask patches with [pcolor = pink] [set plabel count turtles-here]  
end

enter image description here