【问题标题】:Netlogo code problems, turtles can't find patch-at 0,0Netlogo代码问题,乌龟找不到patch-at 0,0
【发布时间】:2013-02-05 02:47:09
【问题描述】:

我正在尝试按照与本视频相同的方式创建一个模拟 (1:29 - 1:45)

https://www.youtube.com/watch?v=pqBSNAOsMDc

我认为实现无限循环过程的一种简单方法是让海龟面向 0,0,然后在半径 90 内寻找空块(所以它们总是向右看。

我得到了错误代码..

'没有定义从点 (3,-6) 到同一点的航向。 '

有人可以用我的代码指出正确的方向吗?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


turtles-own [ faction ]

to setup
  clear-all

  ask patches [ set pcolor white ]
  set-patch-size 7
  resize-world min-pxcor max-pxcor min-pycor max-pycor 


  ask patch 0 0
   [ ask patches in-radius ( max-pxcor * .6) with [  random-float 100 < density ]
     [ sprout 1
         [
         set shape "circle"
         assign-factions
         set color faction-color
         set size 1 ] ] ]

   ask turtles-on patch 0 0 [ die ]

   reset-ticks
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to-report faction-color
   report red + faction * 30
end

to assign-factions
   let angle 360 / factions
   foreach n-values factions [?] [
    ask patch 0 0 [ 
      sprout 1 [
        set heading ? * angle
        ask turtles in-cone max-pxcor angle [ set faction ? + 1 ]
        die ] ] ]
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go 

  ask turtles
  [ set heading (towards patch-at 0 0)  ; adjusts heading to point to centre  
    let empty-patches neighbors with [not any? turtles-here]
    if any? empty-patches in-radius 90
      [ let target one-of empty-patches
        face target
        move-to target ] 
  ]

end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

【问题讨论】:

  • 我不认为要求空补丁in-radius 90 会完成你认为的事情。但我会让你自己弄清楚那部分。你可以随时问另一个问题...

标签: netlogo


【解决方案1】:

在您的go 过程中,您使用的是set heading (towards patch-at 0 0),但patch-at 为您提供了位于相对 位置的补丁,该位置与正在询问的海龟有关。因此,如果您要求patch-at 0 0,您总是会得到海龟实际所在的补丁。并且朝向你自己的方向是不确定的,因此你得到的错误。

patch-at 0 0 替换为patch 0 0(适用于绝对坐标)将解决一半的问题:您所询问的海龟仍有可能已经在patch 0 0。在这种情况下,你会得到和以前一样的错误。

解决方案:将set heading (towards patch-at 0 0) 替换为face patch 0 0。如果您要求面对您已经在的位置,face 原语不会崩溃。

【讨论】:

    【解决方案2】:

    这是因为in-radius 可以return the turtle itself。要解决此问题,只需更改行

    ask patches in-radius .....
    

    ask other patches in-radius .....
    

    【讨论】:

      猜你喜欢
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多