【问题标题】:NetLogo - how do I get all patches the turtle facing?NetLogo - 我如何获得乌龟面临的所有补丁?
【发布时间】:2018-11-26 16:11:40
【问题描述】:

如何获得包含海龟所面对的所有补丁的补丁集?

我知道 patch-ahead 会报告特定距离的补丁。但是,如果我想获得这个方向的所有补丁而不是具有特定距离的单个补丁怎么办?

【问题讨论】:

  • 你的世界被包裹了吗?如果是这样,您是否希望补丁集也环绕包装?
  • 不,它没有包装。谢谢

标签: netlogo


【解决方案1】:

你可以做的是 hatch 一只乌龟并移动它 forward 直到它到达世界的边缘,添加它穿过的所有补丁。

这是一个可见的版本来查看方法:

to testme
  clear-all
  create-turtles 1 [setxy random-xcor random-ycor]
  ask one-of turtles
  [ set pcolor red
    hatch 1
    [ while [can-move? 1]
      [ forward 1
        set pcolor red
      ]
      die
    ]
  ]
end

要实际制作补丁集版本,您需要从当前补丁开始,并在孵化的乌龟移动时添加补丁。试试这个程序版本并演示如何使用它:

turtles-own [ my-path ]

to testme
  clear-all
  create-turtles 1 [setxy random-xcor random-ycor]
  ask one-of turtles
  [ set my-path get-patches-forward self
    print my-path
  ]
end

to-report get-patches-forward [ #me ] ; turtle procedure
  let front-patches patch-here
  hatch 1
  [ while [can-move? 1]
    [ forward 1
      set front-patches (patch-set front-patches patch-here)
    ]
    die
  ]
  report front-patches
end

如果世界被包裹,这将返回错误的答案,因为孵化的乌龟可以无限期地继续前进。相反,您需要检查其坐标,而不是依赖 can-move? 原语。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-24
    • 1970-01-01
    • 2020-04-15
    • 1970-01-01
    相关资源
    最近更新 更多