我试图找出如何检查是否有任何龟靠近另一个(我们将称之为基地龟,或基地)。我需要这个包括对角线,因为我在这些基地周围产卵人,所以需要基地周围空出1个完整的方块。因此.当产卵基地时,我需要确保2个方块内没有其他的基地,包括对角线。
我试过使用 "turtles in-radius (2,3,4,...)",但没有用,因为半径命令似乎是圆形的。我将如何去做呢?
NetLogo的 neighbors
给你乌龟所在的补丁周围的8个补丁。 你是需要周围的16个补丁,还是8个就可以了?
在一个非包装的世界里,一个简单的邻域16的程序可能是
to-report neighbors16
; can be called by a patch or a turtle
; assumes there is no wrapping of the world
let xm max (list (pxcor - 2) min-pxcor)
let xh min (list (pxcor + 2) max-pxcor)
let ym max (list (pycor - 2) min-pycor)
let yh min (list (pycor + 2) max-pycor)
let ptchs no-patches
foreach (range xm (xh + 1) 1) [x ->
foreach (range ym (yh + 1) 1) [y ->
set ptchs (patch-set patch x y ptchs)
]
]
report ptchs with [self != patch [pxcor] of myself [pycor] of myself]
end
希望这能帮助你,查尔斯