对于周长问题,如果我理解您的问题,您可以在面片设置中这样做,以在最大坐标处定义周长:
ask patches with [
pxcor = max-pxcor or
pxcor = min-pxcor or
pycor = max-pycor or
pycor = min-pycor ] [
set pcolor red ;; This setup a red perimeter
]
否则,您可以选择这样的精确坐标(16x16正方形示例):
ask patches with [ pycor >= -16 and pycor >= 16]
[ set pcolor red ]
ask patches with [ pycor <= -16 and pycor <= 16]
[ set pcolor red ]
ask patches with [ pxcor >= -16 and pxcor >= 16]
[ set pcolor red ]
ask patches with [ pxcor <= -16 and pxcor <= 16]
[ set pcolor red ]
然后将其放在巡逻步骤中,以禁止在红色斑块上行走:
ifelse [pcolor] of patch-ahead 1 = red
[ lt random-float 360 ] ;; See a red patch ahead : turn left randomly
[ fd 1 ] ;; Otherwise, its safe to go foward.