NetLogo:斑驳的森林 - 保持总面积和斑点大小稳定且不重叠

时间:2015-09-23 17:56:43

标签: debugging netlogo

我意识到我的问题只是对问题的轻微修改:

但我无法修改它们以满足我的需求。

我需要制作一片斑驳的森林景观。每个设置,“绿色”补丁的总面积必须相同(总计数补丁的20%,10%......),并且一个blob的大小应该相同。因此:blob_size = area / number_blobs

我建议

to create-forests
  clear-all
  ask n-of 1 patches [ set pcolor green ]
  repeat 6 [
    ask one-of patches with [pcolor = green ] [
      ask one-of neighbors4 with [pcolor = black] [ 
        set pcolor green ]
    ]
  ]
end

应该是答案,因为n-of 1 (number_blobs) patches我创建了所需的Blob数量,blob_sizerepeat 6 (blob_size)约束。但是,在我的简单示例中,我有一个error ASK expected input to be an agent or agentset but got NOBODY instead.显然是因为one-of patches with [pcolor = green]没有黑邻居。

请问,如何在我的代码中包含条件ask one-of patches with [pcolor = green ] and with min-one of neighbors4 with [pcolor = black]? 或者有什么不同的方法呢?我需要保持绿色区域的总面积相同,并且补丁大小+ - 同样,如果它们不重叠则最好。非常感谢你!

2 个答案:

答案 0 :(得分:1)

to create-forests
  clear-all
  ask n-of 1 patches [ set pcolor green ]
  repeat 6 [
    ask one-of patches with [pcolor = green and any? neighbors4 with [ pcolor = black ] ] [
      ask one-of neighbors4 with [pcolor = black] [ 
        set pcolor green ]
    ]
  ]
end

答案 1 :(得分:0)

Creating a random shape (blob) of a given area in NetLogo

修改为make-blob
  • 我的斑点仍然可以重叠,但每次运行至少总“面积”是相同的

    to make-blob
      let total_area 500       ;  how patches I want to turn green
      repeat 5 [               ; number of blobs I want to  have
        let blob-maker nobody
        crt 1 [ set blob-maker self     
           setxy random-xcor random-ycor]  ; set random position of "blob-makers"
        repeat 10 [               ; size of one blob (number of patches of the same color close one to another)
        ask blob-maker [
           ask min-one-of patches with [ pcolor = black ] [ distance myself ] [ set pcolor green ]
      rt random 360
      fd 1
    ]
    ]
    ask blob-maker [ die ]
    ]
    end
    

导致

enter image description here