如何使用 Moore 和 Von Neumann 示例中的代码将邻居函数扩展到 24

How to extend neighbor function to 24 using code from Moore and Von Nuemman example

我正在学习如何使用网络徽标,我正在尝试做的一件事是创建一个比代理集 "neighbor" 附带的内置 8 更大的社区 "neighbor"。

我想利用这个扩展社区 运行 与更多邻居一起玩 Conway 的生命游戏。

我已经使用了 netlogo 模型库中可用的生命游戏的内置函数。


to go


  let neighbors24 [list pxcor pycor] of patches with [abs pxcor <= 2 and abs pycor <= 2]


  ask patches
    [ set live-neighbors count neighbors24 with [living?] ]
  ;; Starting a new "ask patches" here ensures that all the patches
  ;; finish executing the first ask before any of them start executing
  ;; the second ask.  This keeps all the patches in synch with each other,
  ;; so the births and deaths at each generation all happen in lockstep.
  ask patches
    [ ifelse live-neighbors = 3
      [ cell-birth ]
      [ if live-neighbors != 2
        [ cell-death ] ] ]
  tick
end

我希望 neighbors24 将相邻单元格的数量从 8 个增加到 24 个,但我遇到了以下错误。

"WITH expected input to be an agentset but got the list [[-2 -1] [0 0] [2 2] [-2 2] [-1 1] [2 -2] [0 2] [-1 -1] [-2 1] [-1 -2] [2 1] [1 0] [-1 0] [-1 2] [1 -1] [0 -1] [-2 0] [0 -2] [1 2] [-2 -2] [1 -2] [0 1] [2 0] [2 -1] [1 1]] instead."

NetLogo 应该会告诉您是哪一行出错了。请将其包含在您以后的问题中。

在这种情况下,错误(大概)是行 set live-neighbors count neighbors24 with [living?]。您的问题是 with 选择指定代理集中满足条件的那些代理。所以 patches with [pcolor = yellow] 会得到黄色补丁。但是,neighbors24 不是一个代理集,它是一个补丁坐标列表。

创建列表是 NetLogo 新手的一个常见错误,特别是如果您有其他编程语言的经验。如果您正在创建代理标识符列表(例如补丁的坐标,或海龟的 who 数字),您几乎肯定需要一个代理集。

修改后的行 let neighbors24 patches with [abs pxcor <= 2 and abs pycor <= 2] 将创建 neighbors24 作为代理集。