2013-02-04 70 views
4

我想创建沿同一类型的线,因为这视频的模拟(1:29 - 1:45)的NetLogo代码的问题,海龟找不到补丁在0,0

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

我认为一个简单的方法来实现一个无限循环procress将是使海龟面对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 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
+0

我不认为要求空半径90英寸的半径将实现你的想法。但我会让你为自己弄清楚这一部分。你总是可以问另一个问题... –

回答

0

这是因为in-radius可以return the turtle itself。为了解决这个问题只需要改变线路

ask patches in-radius ..... 

ask other patches in-radius ..... 
2

在你go过程中,使用的是set heading (towards patch-at 0 0),但patch-at给你的位置相对到在问乌龟补丁。所以如果你要求patch-at 0 0你总是会得到乌龟实际上的补丁。而对自己的标题是不确定的,因此你得到的错误。

patch 0 0替换patch-at 0 0(它与绝对坐标一起工作)将解决您的一半问题:您所问的龟仍然有可能已经在patch 0 0。在那种情况下,你会得到和以前一样的错误。

解决方法:用face patch 0 0替换set heading (towards patch-at 0 0)。如果你要求面对你已经在的位置,face基元不会崩溃。