在Netlogo中是否可以创建由补丁颜色定义的边界?

时间:2017-10-30 10:07:15

标签: model move netlogo patch turtle-graphics

我试图让我的海龟“巡逻”环境的某个区域但是当我添加代码来包含它们时,它们会走到领土的边缘然后停下来并且蜱也会停止。

相反,如果他们的“能量”变量低于[x]

,是否有可能让他们离开领土?

1 个答案:

答案 0 :(得分:2)

对于周边问题,如果我理解你的问题,你可以在补丁设置中这样做,以在最大坐标处定义一个边界:

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.