Netlogo 将一组补丁分配给一个品种的自己的变量

Netlogo assign group of patches to own variable of a breed

我是 netlogo 的新手,想知道如何将一组补丁设置为特定品种的自变量。例如,假设我有:

breed [ buildings building ]
buildings-own [ my-patches ]

我希望能够拥有一组分配给每个建筑物的 my-patches 字段的补丁(假设是一个矩形,因此受到某些坐标的约束)。我该怎么做?

您需要知道的第一件事是您不能拥有不同种类的补丁。虽然你没有说那是你想要的,但我只是想确保你知道这一点。

看看这段代码。这是一个完整的程序,它创建了一些海龟(称为房地产经纪人)并为它们分配了一些补丁。然后它将这些补丁变成与房地产经纪人相同的颜色。

breed [realtors realtor]
realtors-own [my-patches]

to setup
  clear-all
  create-realtors 10
  [ setxy random-xcor random-ycor
    set size 2
    set shape "circle"
    set my-patches n-of 5 patches in-radius 3
  ]
  ask realtors [ask my-patches [set pcolor [color] of myself ] ]
  reset-ticks
end

您可以 运行 通过为 'setup' 创建一个按钮或在命令中心简单地输入设置。

欢迎使用 Stack Overflow 和 Netlogo!给定你的品种和上面的 buildings-own,你可以简单地使用 set 来分配你想要建筑物的 my-patches 变量保存的 patch-set

to setup
  ca
  ask patches with [ pxcor mod 10 = 0 and pycor mod 10 = 0 ] [
    sprout-buildings 1 [ 
      set shape "square"
      set heading 0
      set size 1.5
      set my-patches patches with [ 
        pxcor > [pxcor] of myself - 3 and
        pxcor < [pxcor] of myself + 3 and 
        pycor > [pycor] of myself - 3 and
        pycor < [pycor] of myself + 3
      ]
      ask my-patches [
        set pcolor [color] of myself - 2
      ]
    ]
  ]
  reset-ticks
end