有没有办法在 NetLogo 中创建不可逾越的障碍?

Is there a way to create impassable barriers in NetLogo?

我正在尝试编写一种寻路行为,其中代理将在环境中找到最佳补丁并绕过栅栏导航以到达所述补丁。我创建了一个补丁变量 'f',设置为 1 表示栅栏,0 表示任何其他补丁。

我想让这些栅栏无法通过(即我希望它们成为代理人不会用于移动的补丁),但代理人似乎仍然能够在某种程度上通过它们旅行,在某些情况下甚至能够完全跨越它们。

Here is a picture of an agent crossing a barrier I don't want it to cross

代理商相关决策代码如下:

{let moveset patches in-radius 30 with [f = 0 and n > 0]

let target max-one-of moveset [n]

 ifelse patch-here != target 
 [ 
  set heading towards target

  ]
 []

let chance random-float 10
if chance >= 5 [let pick -145]
if chance < 5 [let pick 145] 

ask patches in-radius 1 
[if f = 1 
[ask myself

  [set heading towards min-one-of patches [distance myself] + 180 - random 10 + random 10 ]

]
]

fd 1}

为了清楚起见,'n' 只是一个变量,用于表示我希望我的代理人找到并冒险去的补丁。

有人知道 NetLogo 中有一种简单的方法可以将某些补丁排除在决策过程中作为移动的可行区域(即硬障碍)吗?

如果您还没有,请查看模型库中的 "Look Ahead" 示例 - 这是使用色块颜色控制海龟移动的简单演示。下面是一些基于该模型的代码。使用此设置:

breed [ seekers seeker ]
breed [ goals goal ]
patches-own [ steps-from-goal ]

to setup
  ca
  ask patches [ 
    set steps-from-goal 999
  ]
  ask patches with [ pxcor mod 10 = 0 ] [
    set pcolor red
  ]
  ask patches with [ pycor mod 10 = 0 ] [
    set pcolor black
  ]
  ask one-of patches with [ pcolor = black ] [
    sprout-seekers 1 [
      set color blue
      pd
    ]
  ]
  ask one-of patches with [ pcolor = black ] [
    sprout-goals 1 [
      set color white
      set shape "circle"
    ]
  ] 
  reset-ticks
end

您可以让 seekers 品种在黑色方块周围游荡,直到它们与 goal 乌龟共享一个补丁:

to random-wander 
  ask seekers [
    if any? goals-here [
      stop
    ]
    rt random 61 - 30
    ifelse can-move? 1 and [pcolor] of patch-ahead 1 = black [ 
      fd 1
    ] [
      rt one-of [ 90 -90 ]
    ]
  ]
  tick
end

但是,请注意,海龟仍然可以使用此方法 'jump' 补丁的角,因为它们能够以任何角度评估 patch-ahead 1 - 因此,补丁一 space前面的一只乌龟可能会被评估穿过另一块补丁的角落。乌龟实际上永远不会落在禁止的补丁上,但您可能会注意到它们的路径可以穿过那些被阻止的补丁。

编辑:

参见 "traps" 方笼中的乌龟的简化代码:

to setup
  ca
  crt 1 [ 
    setxy 5 5
    set heading 180
    repeat 4 [
      repeat 10 [
        ask patch-here [ set pcolor red ]
        fd 1 
      ]
      rt 90
    ]
    die
  ]

  crt 1 [ pd ]
  reset-ticks
end

to go
  ask turtles [
    rt random 61 - 30
    ifelse can-move? 1 and [pcolor] of patch-ahead 1 = black [
      fd 1
    ] [
      rt one-of [ 90 -90 ]
    ]
  ]
  tick
end

1100 个刻度后:

13300 个刻度后: