我正在学习如何使用网络标志,我正在尝试做的一件事是创建一个更大的社区,然后是内置的 8 与代理集“邻居”一起提供。
我想用这个扩展的社区与更多的邻居一起运行康威的生命游戏。
我使用了 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
我希望neighbor24 将相邻单元格的数量从8 个增加到24 个,但我遇到了以下错误。
“预期输入是一个代理集,但得到了列表 [[-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]]。”
NetLogo 应该告诉您哪一行给了您错误。请在您以后的问题中包括这一点。
在这种情况下,错误(大概)是 line set live-neighbors count neighbors24 with [living?]
。您的问题是with
在指定的代理集中选择满足条件的那些代理。所以patches with [pcolor = yellow]
会得到黄色补丁。然而,neighbor24 不是一个代理集,它是一个补丁坐标列表。
创建列表是 NetLogo 新手的一个常见错误,特别是如果您有其他编程语言的经验。如果您正在创建代理标识符列表(例如补丁的坐标或who
海龟的数字),您几乎肯定需要一个代理集。
修改后的行将let neighbors24 patches with [abs pxcor <= 2 and abs pycor <= 2]
创建邻居 24 作为代理集。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句