每个补丁间隔的海龟

时间:2014-10-26 15:28:57

标签: netlogo agent

  to create-wall
  set breadth-patches patches with[(pycor > (-(breadth)) and pycor < breadth and pxcor = lengthrec) or(pycor > (-(breadth)) and pycor < breadth and pxcor = (-(lengthrec))) ]
  set length-patches patches with[(pxcor > (-(lengthrec)) and pxcor < lengthrec and pycor = (-(breadth - 1))) or (pxcor > (-(lengthrec)) and pxcor < lengthrec and pycor = (breadth - 1))]
  set gap-patches patches with [pxcor > (gap * (-1)) and pxcor < gap and pycor =(breadth - 1)]
  set length-patches length-patches with [not member? self gap-patches]
  ask breadth-patches[

    sprout-walls 1[set color 2
      set size 0.5 set heading 180 fd 0.25
      if-else(pxcor < 0)[set heading 90][set heading 270] fd 0.25]
    sprout-walls 1[set color 2
      set size 0.5 set heading 360 fd 0.25
     if-else(pxcor < 0)[set heading 90][set heading 270] fd 0.25]

    ]
  ask length-patches[
   sprout-walls 1[
         set color 2
         set size 0.5 set heading 90  fd 0.25
         if-else(pycor < 0)
           [
              set heading 180] 
           [ 
                set heading 0] 
         fd 0.25
         ]
   sprout-walls 1[
          set color 2
          set size 0.5 
          set heading 270 
          fd 0.25
          if-else(pycor < 0)
            [
                set heading 180]
            [
              set heading 0] fd 0.25
     ]
   ]  
end

以上创建如下框:

enter image description here

因此,每个补丁有两个海龟/墙壁。我希望将它增加到三个或者如果可能的话写一个代码,我可以将每个补丁的海龟/墙的数量变量作为变量。

感谢。

1 个答案:

答案 0 :(得分:1)

如果我理解你正在做什么,那么将sprout-wall中的1更改为变量应该这样做。 设置3

Sprout-wall a [... stuff ..]

A也可以是输入或滑块变量。

将它们随机散布在补丁中。

将其放入萌芽

Setxy (xcor + random-float 1 - .5) (ycor + random-float 1 - .5)

要将它们排成一行,我将把它写成一个程序

to Make-line [number orientation]
  Let c 0 ;; this is a counter
  Crt 5
  [  
  ;; your create code goes here
  Let c c + 1
  Set heading orientation bk .5 fd ( c / ( number + 1)  
  ]
End

数字是你想要的海龟数量水平在0垂直90°