netlogo 海龟在范围内时直接移动到另一只海龟

netlogo turtles move directly to another turtle when in range

这是猛禽和人类的捕食者猎物模拟。我希望猛龙队在射程内直接移动到最近的人。如何在 netlogo 中实现这个?有什么建议吗?

假设您想要范围为 5,并且假设您希望猛禽每刻向最近的人类移动一步。那么:

ask raptors [
  let candidates humans in-radius 5
  if any? candidates [
    let target min-one-of candidates [distance myself]
    face target
    fd 1
  ]
]

要为 Seth 的建议添加一个替代方案,如果您希望猛禽立即移动到目标人类,然后立即吃掉他们,您可以尝试:

ask raptors [
   let candidates humans in-radius 5
   if any? candidates [
   let target min-one-of candidates [distance myself]
      move-to target
      ask target [die]
  ]
]     

如果你想让猛禽获得任何东西(能量等),你可以把它放在 move-to 和 ask target 命令之间的一行中。如果你想让人类在被吃掉时做任何事情(对其他人大喊 运行 等),你可以将其放在 ask target 命令之后的括号中,但要确保将其放在 die 之前,否则die 命令首先执行。