Netlogo Conways邻居中的扩展邻居未在自定义代理集中读取
我试图写一个康威的《生命游戏》的版本,它不是看相邻的8个细胞,而是看相邻的24个细胞。(不是围绕中心的1个正方形,而是看2) 我听从了一些建议,建立了一个“邻居24”代理,应该查看活细胞周围的细胞Netlogo Conways邻居中的扩展邻居未在自定义代理集中读取,netlogo,Netlogo,我试图写一个康威的《生命游戏》的版本,它不是看相邻的8个细胞,而是看相邻的24个细胞。(不是围绕中心的1个正方形,而是看2) 我听从了一些建议,建立了一个“邻居24”代理,应该查看活细胞周围的细胞 patches-own [ living? ;; indicates if the cell is living live-neighbors ;; counts how many neighboring cells are alive ] to setup-blank
patches-own [
living? ;; indicates if the cell is living
live-neighbors ;; counts how many neighboring cells are alive
]
to setup-blank
clear-all
ask patches [ cell-death ]
reset-ticks
end
to setup-random
clear-all
ask patches
[ ifelse random-float 100.0 < initial-density
[ cell-birth ]
[ cell-death ] ]
reset-ticks
end
to cell-birth
set living? true
set pcolor fgcolor
end
to cell-death
set living? false
set pcolor bgcolor
end
to go
let neighbors24 patches with [abs pxcor <= 2 and abs pycor <= 2]
ask patches
[ set live-neighbors count neighbors24 with [living?] ]
ask patches
[ ifelse live-neighbors = 3
[ cell-birth ]
[ if live-neighbors != 2
[ cell-death ] ] ]
tick
end
to draw-cells
let erasing? [living?] of patch mouse-xcor mouse-ycor
while [mouse-down?]
[ ask patch mouse-xcor mouse-ycor
[ ifelse erasing?
[ cell-death ]
[ cell-birth ] ]
display ]
end
自己的补丁程序[
存活?;;指示细胞是否存活
活的邻居;;计算有多少相邻的细胞是活的
]
设置空白
清除所有
问补丁[细胞死亡]
重置滴答声
结束
随机设置
清除所有
询问补丁
[ifelse随机浮动100.0<初始密度
[细胞出生]
[细胞死亡]]
重置滴答声
结束
细胞出生
开始生活?真的
设置pcolor fgcolor
结束
细胞死亡
开始生活?假的
设置pcolor bgcolor
结束
外带
让[abs pxcor的邻居24个补丁所有的细胞都在死亡,因为他们不是在计算自己周围的活细胞,而是在原点周围的活细胞。按如下方式编辑代码:
to go
let neighbors24 patches with [abs pxcor <= 2 and abs pycor <= 2]
type "Live patches near centre: " print count neighbors24 with [living?]
ask patches
...
要走了
使用[abs pxcor让邻居24个补丁我对你的go
程序做了一些小的调整,一些输入来自NetLogo模型库中的Moore&Von Naumann邻居示例。有关调整的更多详细信息,请查看下面代码中的注释
to go
;; creates a list with patches of the surrounding 24 patches
;; with the caller included.
let neighbors24 [list pxcor pycor] of patches with [abs pxcor <= 2 and abs pycor <= 2]
;; uncomment the line below, if you don´t want to consider the caller
;; patch to adjust the neighbors24 set
;set neighbors24 remove [0 0] neighbors24
;; for illustration, shows the number of coordinates considered as neighbors
;show length neighbors24
;; for illustration, shows the patch coordinates of the neighbors24 set
;show neighbors24
ask patches [
;; each patch checks the the "living" neighbors at the given coordinates (relative to this agent).
;; Check documentation of "at-points"
set live-neighbors count patches at-points neighbors24 with [living? = true]
]
ask patches
[ ifelse live-neighbors = 3
[ cell-birth ]
[ if live-neighbors != 2
[ cell-death ] ] ]
tick
end
要走了
;;创建包含周围24个面片的面片的列表
包括打电话的人在内。
让邻居24[列出pxcor-pycor]的补丁和[abs-pxcor]我有一种预感,这就是发生的事情,似乎我误解了代码在活细胞中的读取方式。谢谢你的反馈!