我试图让我的 turtle “巡逻”环境的某个区域,但是当我添加代码来包含它们时,它们会走到区域的边缘,然后停下来,蜱虫也会停止。
相反,如果他们的“能量”变量低于[x],是否可以允许他们离开领土
最佳答案
对于周长问题,如果我理解你的问题,你可以在补丁设置中这样做,以在最大坐标处定义周长:
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 ]
然后将其放在您的巡逻台阶中以禁止在红色斑 block 上行走:
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.
关于model - Netlogo 中是否可以创建由补丁颜色定义的边界?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47012626/