我想使这些围栏无法通行(即我希望它们成为特工不会使用的补丁),但特工似乎仍然能够在一定程度上行进,在某些情况下甚至能够完全移动穿过他们。
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中有一种简单的方法来将某些补丁排除为决策过程中可行的移动区域(即硬障碍)吗?
答案 0 :(得分:1)
如果还没有,请看一下模型库中的“向前看”示例-这是使用色块颜色控制乌龟移动的简单演示。下面是基于该模型的一些代码。使用此设置:
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
但是,请注意,海龟仍可以使用此方法“跳动”斑块的角,因为它们能够以任何角度评估patch-ahead 1
-因此,可能会在整个海龟之前的一个斑块处评估另一个补丁的角落。乌龟从不应该真正落在禁止的补丁上,但是您可能会注意到它们的路径可以穿越那些被阻止的补丁。
编辑:
请参见在方形笼子中“捕获”一只乌龟的简化代码:
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次滴答之后: