【问题标题】:Using the commands "heading", "random" and "random-float" in NetLogo在 NetLogo 中使用命令“heading”、“random”和“random-float”
【发布时间】:2021-09-17 13:24:47
【问题描述】:

我对一些 NetLogo 命令有疑问。

我在 NetLogo 中有一个封闭的世界(方框)。一部分代码有两种walks。

步行 1:

right random 360
let x 2
forward x

步行 2:

set heading random-float 360
set real-x real-x + dx
set real-y real-y + dy      
let x 2
forward x
  1. on the walk 1:问题是当一个代理到达世界边缘(封闭世界)时,代理会一点一点地转身,直到他变成世界并再次开始行走。但是,如果我将代码行 right random 360 更改为 right random-float 360。蜜蜂不会一点一点地转身,直到它找到世界的内部并再次开始移动。谁能解释一下为什么会这样?

  2. 在第 2 步:问题是一些特工到达了世界的边缘,没有死,也没有做任何其他事情。如果我将 set heading random-float 360 代码行从 walk 2 更改为 right random-float 360。代理不会死。谁能向我解释为什么会这样?

我已经在 NetLogo 字典中阅读了以下命令:“random”、“random-float”和“heading”,但我不明白为什么会在我的代码中发生这种情况。如果有人能帮助我理解这些命令,我​​将不胜感激。

提前致谢

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    我无法重现您描述的行为。考虑以下玩具模型:

    to setup
      ca
      reset-ticks
      crt 2 [ pd ]
    end
    
    to go-1
      ask turtles [
        right random 360
        fd 2
      ]
      tick
    end
    
    to go-2
      ask turtles [
        set heading random-float 360
        forward 2
      ]
      tick
    end
    

    我可以运行go-1go-2 'forever' 并且海龟似乎不会被卡住。你能提供更多细节(包括你的turtlesdie的代码)吗?

    【讨论】:

    • 是的,我会尽量缩短要发布的代码。但是,到目前为止我注意到的是:在 walk 1 问题中,代理在边缘时一点一点地转身,我认为这与使用“face”命令和正确的随机 360 度有关但是,当我将“face”与正确的 random-float 360 命令结合使用时,不会发生这种情况。至于餐饮服务2,我仍然不知道代理不死会发生什么。我将尝试简化代码以在此处发布
    • 由于“face”也设置了标题,因此查看“face”出现的位置和时间会很有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多