在我的模型中,海龟从地图的右侧移动到左侧。在它们穿行的过程中,它们正在寻找绿色的斑块。当他们找到一个,并且它在他们的视锥中时,他们会转身朝它走去。如果有多个等距的补丁,他们会随机选择去哪个补丁。然而,当它们移动时,它们的运动中似乎有很多不必要的抖动。有人能说出原因吗?看看这张照片,http://imgur.com/qOftVPJ。他们应该一直往前走直到他们看到绿色。
to move-bug
ask bugs [
count-steps
if pxcor = min-pxcor [
file-open data-filename
file-type data-filename
file-type " "
file-type data-header
file-write vision-width
file-write vision-distance
file-write greenroof-percent
file-write gray-steps
file-write green-steps
file-write steps
file-type "\n"
file-close
]
if pxcor = min-pxcor [die]
set heading 270
pen-down
let green_target nobody
let perceived_patches patches in-cone vision-distance vision-width
set green_target perceived_patches with [ pcolor = green ]
ifelse count green_target > 0 [face min-one-of green_target [vision- distance]][face min-one-of perceived_patches [vision-distance]] ;; added equivalent jitter to non-green squares前进1]
end发布于 2017-02-16 08:28:39
Ifelse将运行您为其提供的两个命令块中的一个,因此每次运行此过程时,bug都会面对绿色目标补丁(如果绿色补丁在其视线范围内)或感知到的补丁(如果bug看不到任何绿色补丁)。因此,如果移动错误的过程是在move-bug之后调用的,错误将会抖动,因为在实际移动之前,无论运行哪个face行,错误的标题都会发生变化。你真正想要的是让bug只在看到绿色补丁时才面对补丁,所以试着只使用if语句而不是ifelse。此外,您正在使用
min-one-of green_target [vision-distance]
但是你可能想要
min-one-of green_target [distance myself]
选择最近的绿色补丁。我得到了下面的代码来为我工作,但需要注意的是,我只是在我的字段(see image- bugs here move right to left)上随机放置了绿色圆圈。
set heading 270
pd ;; shorthand for pen-down
let green_target nobody
let perceived_patches patches in-cone vision-distance vision-width
set green_target perceived_patches with [ pcolor = green ]
print green_target
if count green_target > 0 [
face min-one-of green_target [ distance myself ]
]
fd 1https://stackoverflow.com/questions/42261513
复制相似问题