每次海龟在Netlogo中移动后,我如何改变它们的方向?
在我的模型中,海龟从地图的右侧移动到左侧。当他们穿越时,他们正在寻找绿色的斑块。当他们找到一个,它就在他们的视野范围内,他们转向它。如果有多个等距的面片,它们会随机选择要转到的面片。然而,当它们移动时,它们的移动似乎有很多不必要的抖动。有人知道为什么吗?偷看这张照片。他们应该一直往前走,直到看到绿色为止每次海龟在Netlogo中移动后,我如何改变它们的方向?,netlogo,Netlogo,在我的模型中,海龟从地图的右侧移动到左侧。当他们穿越时,他们正在寻找绿色的斑块。当他们找到一个,它就在他们的视野范围内,他们转向它。如果有多个等距的面片,它们会随机选择要转到的面片。然而,当它们移动时,它们的移动似乎有很多不必要的抖动。有人知道为什么吗?偷看这张照片。他们应该一直往前走,直到看到绿色为止 to move-bug ask bugs [ count-steps if pxcor = min-pxcor [ file-open data-filenam
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
每次bug移动时,它都会运行
ifelse count green\u target
块Ifelse
将运行您提供给它的两个命令块中的一个,因此每次运行此过程时,bug都会面对一个绿色的目标补丁(如果绿色补丁在其视野范围内)或一个感知到的补丁(如果没有绿色补丁对bug可见)。因此,如果移动bug的过程在move bug
之后调用,那么bug将抖动,因为它的标题会因实际移动之前运行的face
行而改变。实际上,您希望bug只在看到绿色补丁时才面对补丁,所以尝试使用if语句而不是ifelse。此外,您正在使用
最小一个绿色目标[视距]
但是你可能想要
min one of green\u目标[距离我自己]
选择最近的绿色面片。我得到了下面的代码来为我工作,我只是在我的字段()上随机放置了绿色圆圈
非常感谢你!
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 1