【问题标题】:If patch does not exist, random left turn. If patch does exist, and color is orange or green, move toward that patch如果补丁不存在,随机左转。如果补丁确实存在,并且颜色是橙色或绿色,则向该补丁移动
【发布时间】:2016-12-02 21:02:42
【问题描述】:

我在执行此代码时遇到问题,希望有人能提供帮助。正如标题所说,我的问题是移动人(海龟)。如果前面的补丁不存在,则随机左转。如果前面的补丁确实存在,并且是绿色或橙色,则朝着该补丁移动,如果它不是绿色或橙色,则随机左转。

这是我的代码:

ifelse is-patch? patch-ahead 1
and member? pcolor [green orange]] of patch-ahead 1
[fd 1]
[lt random 1]

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    试试这个:

    to setup
    create-turtles 1 [ set color green ]
    end
    
    to move
    ask turtles [
      let ahead patch-set patch-ahead 1
    ifelse 
      any? ahead and any? ahead with [pcolor = black or pcolor = green]
      [fd 1]
      [lt random 1]
    ]
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多