在netlogo中,我有四只乌龟,一只Pacman乌龟和3只幽灵,它们会尝试通过使用它应该在变量内部报告的位置来追踪吃豆子,但我无法理解如何找回吃豆子龟的位置并将其存储在变量中。这个变量应该随着Pacman的每次移动而更新,以便幽灵被吸引到Pacman所在的最新补丁位置。
更新:我使用patch-here命令检索pacman的位置并将其存储在名为" PacManLocation"的全局变量中。这是正确的吗?如果是这样的话,我怎么能让我的鬼龟一次一步地去那个特定的补丁呢?我已经尝试过前进命令写作"转发PacManLocation"但我得到一个错误,说它期望数字输入。
以下是原始代码:
to PlayGame
ask ghostsOne [
face min-one-of patches with [ pcolor = blue ] [ distance PacManLocation ] forward 0.7
]
ask ghostsTwo [
face min-one-of patches with [ pcolor = blue ] [ distance PacManLocation ] forward 0.7
]
ask ghostsThree [
face min-one-of patches with [ pcolor = blue ] [ distance PacManLocation ] forward 0.7
]
end
答案 0 :(得分:2)
这应该让你开始。 (未经测试。)
to PlayGame
;;it is better to make a ghosts breed or at least use a global,
;;but here we stick with what you have
let ghosts (turtle-set ghostsOne ghostsTwo ghostsThree)
ask ghosts [move]
end
to move
if (blue != [pcolor] of patch-ahead 0.7) [
face min-one-of neighbors with [pcolor = blue] [distance PacManLocation]
]
fd 0.7
end