0

想象一个有街道的城市,人们在城市和街道周围移动。我怎么能对只以某种方式移动或不以某种方式移动(补丁)的海龟说?

4

1 回答 1

1

我建议您查看和研究模型库的代码示例部分中的一些相关模型:

  • 向前看示例:海龟在移动之前先看它们,以免踩到蓝色斑块
  • 墙跟随示例:海龟将棕色斑块视为“墙”,并在它们旁边行走

在 Look Ahead Example 中,关键的海龟代码片段是:

ifelse [pcolor] of patch-ahead 1 = blue
  [ lt random-float 360 ]   ;; We see a blue patch in front of us. Turn a random amount.
  [ fd 1 ]                  ;; Otherwise, it is safe to move forward.

在墙跟随示例中,海龟的行为更复杂,因此代码也更复杂。

于 2013-10-25T21:12:20.340 回答