【发布时间】:2016-06-13 18:56:02
【问题描述】:
我试图让带有任何标题(随机 360 度)的海龟避开带有红色的斑块。但是,我观察到如果要求海龟移动“fd 1 + random-float 2.0”,那么当前面有一个红色补丁时,有时海龟会转动(设置航向 - 180),有时(甚至大多数时候)不会转动。此外,当我要求海龟移动“fd 1”或“fd 0.1 + random-float 0.9”时,代码一切正常。 希望背后的原因是我要求海龟一步移动的补丁数量。移动“fd 0.1 + random-float 0.9”的下一个补丁是什么,我该怎么做这与patch-ahead 1一起工作。我的代码和界面已添加。
to setup
clear-all
ask patches [set pcolor green ]
ask patches with [pycor = 3] [set pcolor red]
create-turtles 40
[
set color blue
set xcor random-pxcor
set ycor random-pycor
set heading random 360
set size 1
set speed 1 + random-float 2.0
]
end
to go
ask turtles [
fd speed
avoid-walls
]
end
to avoid-walls
if [pcolor] of patch-ahead 1 = red [set heading heading - 180]
end
【问题讨论】:
-
您只是向前看 1 个单位,但可能会移动 3.0 个单位。您的红色条带需要比乌龟所能做出的最大移动更宽,或者您需要检查前方的一系列空间,而不仅仅是一个固定点。
-
谢谢@MarcB,我明白了。
标签: netlogo