【问题标题】:How to ask turtles to avoid a patch with specific color at patch-ahead 1 but turtles move forward by bigger number (not fd 1) in one step in NetLogo如何让海龟在 NetLogo 中一步避开具有特定颜色的补丁 1 但海龟向前移动更大的数字(不是 fd 1)
【发布时间】:2016-06-13 18:56:02
【问题描述】:

我试图让带有任何标题(随机 360 度)的海龟避开带有红色的斑块。但是,我观察到如果要求海龟移动“fd 1 + random-float 2.0”,那么当前面有一个红色补丁时,有时海龟会转动(设置航向 - 180),有时(甚至大多数时候)不会转动。此外,当我要求海龟移动“fd 1”或“fd 0.1 + random-float 0.9”时,代码一切正常。 希望背后的原因是我要求海龟一步移动的补丁数量。移动“fd 0.1 + random-float 0.9”的下一个补丁是什么,我该怎么做这与patch-ahead 1一起工作。我的代码和界面已添加。

to setup
    clear-all
    ask patches [set pcolor green ]
    ask patches with [pycor = 3] [set pcolor red]

   create-turtles 40      
   [ 
      set color blue
      set xcor random-pxcor
      set ycor random-pycor
      set heading random 360
      set size 1
      set speed 1 + random-float 2.0
  ]
end

to go
  ask turtles [
    fd speed
    avoid-walls
  ]
end

to avoid-walls
   if [pcolor] of patch-ahead 1 = red [set heading heading - 180]
end

【问题讨论】:

  • 您只是向前看 1 个单位,但可能会移动 3.0 个单位。您的红色条带需要比乌龟所能做出的最大移动更宽,或者您需要检查前方的一系列空间,而不仅仅是一个固定点。
  • 谢谢@MarcB,我明白了。

标签: netlogo


【解决方案1】:

Try using in-cone 而不是预先修补

to avoid-walls
   let front-patches patches in-cone 2 75
   if pcolor of one-of front-patches = red [set heading heading - 180]
end

【讨论】:

  • 谢谢,我试过了,但都一样。正如@MarcB 在我使红色补丁大小等于 3 个单位后建议的那样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多