【问题标题】:How can I get Netlogo turtle coordinates which can then be used by the other turtles to navigate them to that turtle?如何获得 Netlogo 海龟坐标,然后其他海龟可以使用该坐标将它们导航到该海龟?
【发布时间】:2014-12-14 15:30:21
【问题描述】:

在 netlogo 中,我有四只海龟、一只吃豆人海龟和 3 只幽灵,它们将尝试使用应该在变量中报告的位置来追踪吃豆人,但我不明白如何检索吃豆人海龟的位置并将其存储在变量中。这个变量应该随着吃豆人的每一个动作而更新,以便鬼魂被吸引到吃豆人所在的最新补丁位置。

更新:我使用 patch-here 命令检索 pacman 的位置并将其存储在名为“PacManLocation”的全局变量中。这是正确的,如果是这样,我怎样才能让我的鬼龟一步一步地去那个特定的补丁?我已经尝试过编写“forward 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

【问题讨论】:

  • 我已经使用patch-here 命令来检索pacman 的位置并将其存储在一个名为“PacManLocation”的全局变量中。这是正确的吗?如果是这样,我怎样才能让我的鬼龟一步一步地去那个特定的补丁?我已经尝试过写“forward PacManLocation”的转发命令,但我收到一个错误,说它需要一个数字输入。
  • 添加您在问题中尝试的代码,它会更容易。不要犹豫,看看stackoverflow.com/help/how-to-ask & stackoverflow.com/help/mcve ;)
  • 最好不要把代码放在注释里;尽你所能,它变得非常难以阅读。 Stack Overflow 可让您修改问题。修改您的问题以包含代码。

标签: netlogo


【解决方案1】:

这应该可以帮助您入门。 (未测试。)

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

【讨论】:

    猜你喜欢
    • 2015-04-16
    • 1970-01-01
    • 2013-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多