首页 > 解决方案 > 我怎么能让乌龟沿着路走去目的地

问题描述

最近我发现了帮助海龟沿着我指定颜色不是黑色的道路行走的代码。

let target one-of patches in-cone 1.5 180 with [pcolor != black]
if target != nobody
  [
    face target
    move-to target
  ]

但我的问题是

  1. 当乌龟遇到死胡同时,它就停在那里不动了。

  2. 我的乌龟已经有了自己的目的地(这个模型是另一个)。如果我使用我之前提到的代码,也许它不起作用。那么我该如何解决这个问题呢?

这是我写的一些代码(另一个模型)。

ask turtles
  [
    set wlocation one-of patches with [pcolor = pink]
    move-to wlocation
    set myhome wlocation
  ]

之后,我会让海龟在模型中四处游荡。然后在某个特定的时间,海龟会通过下面的代码回到它的家。当乌龟到达它的家时,它会保持静止。

ifelse distance myhome > 2
  [face myhome fd random 3]
  [wander]

to wander
  ifelse random 2 = 0 [rt random 30] [lt random 30]
end

有没有人有任何想法或建议?

标签: netlogo

解决方案


推荐阅读