NetLogo中的运行时错误,turtles试图打开';朝向';但是没有人可以代替

NetLogo中的运行时错误,turtles试图打开';朝向';但是没有人可以代替,netlogo,Netlogo,请大家帮个大忙。我还有最后一个bug要在代码中消除,然后就完成了 我所有这些代码的目的是,如果附近有一块空地,就把所有的海龟搬走。有间隙的海龟,然后在其邻居的任何地方有一只海龟4,根据扩展邻居的J值,会转向或远离间隙后的海龟。所有其他的海龟都搬到附近的另一个广场上 我在转动海龟时遇到了问题。它们通常都很好,只是偶尔我会出错,说乌龟试图转向任何人。我不明白为什么会发生这种情况,因为据我所知,只有有缝隙的乌龟和后面的乌龟被要求转向,所以它们应该总是有一个“某人”来转向 世界已经被包围了。我还试着用“

请大家帮个大忙。我还有最后一个bug要在代码中消除,然后就完成了

我所有这些代码的目的是,如果附近有一块空地,就把所有的海龟搬走。有间隙的海龟,然后在其邻居的任何地方有一只海龟4,根据扩展邻居的J值,会转向或远离间隙后的海龟。所有其他的海龟都搬到附近的另一个广场上

我在转动海龟时遇到了问题。它们通常都很好,只是偶尔我会出错,说乌龟试图转向任何人。我不明白为什么会发生这种情况,因为据我所知,只有有缝隙的乌龟和后面的乌龟被要求转向,所以它们应该总是有一个“某人”来转向

世界已经被包围了。我还试着用“小心”来检查如果我越过了错误,会发生什么,而“脸”也会得到同样的错误。这可能很简单,但我就是做不出来

     to go  
        ask turtles 
           [ move-turtle]
          tick
    end

    to move-turtle
      let vacant-patches neighbors4 with [not any? turtles-here ]  
      ifelse any? turtles with  [(count turtles at-points [ [ 0 2 ] ]  = 1 ) and 
(count turtles at-points  [ [ 0 1] ] = 0 )  
                          or (count turtles at-points [ [-2 0] ] = 1 ) and 
(count turtles at-points  [ [-1 0] ] = 0 ) 
                          or (count turtles at-points [ [2 0] ]  = 1 ) and 
(count turtles at-points [ [1 0] ] = 0 ) 
                          or (count turtles at-points [ [0 -2] ]  = 1 ) and 
(count turtles at-points [  [0 -1] ]= 0 ) ]                   
                     [turn-turtle 
                       if can-move? 1 and not any? turtles-on patch-ahead 1 
                       [move-to patch-ahead 1]] 
                     [ move-to one-of vacant-patches ]
      set JBB 0
      set JSS 0 ;;not sure if I need to do this either? 
        end

    to turn-turtle
      let target-heading 0                                         
      if any? bigs with     [(count bigs at-points  [[0 2]]  = 1 ) and 
(count turtles at-points [ [ 0 1]] = 0 ) 
                          or (count bigs at-points [[-2 0]]  = 1 ) and 
(count turtles at-points  [[-1 0] ]= 0 ) 
                          or (count bigs at-points [[2 0] ] = 1 ) and 
(count turtles at-points[ [1 0] ]= 0 ) 
                          or (count bigs at-points [[0 -2]]  = 1 ) and 
(count turtles at-points  [ [0 -1] ]= 0 ) ]
                          [ask bigs at-points [[0 2] [-2 0] [2 0] [0 -2]] [set JBB 0.7 ]]                                          
       if any? smalls with     [(count smalls at-points [ [ 0 2 ] ]  = 1 ) and 
(count turtles at-points  [ [ 0 1] ] = 0 ) 
                          or (count smalls at-points [ [-2 0] ] = 1 ) and 
(count turtles at-points  [ [-1 0] ] = 0 ) 
                          or (count smalls at-points [ [2 0] ]  = 1 ) and 
(count turtles at-points [ [1 0] ] = 0 ) 
                          or (count smalls at-points [ [0 -2] ]  = 1 ) and 
(count turtles at-points [  [0 -1] ]= 0 ) ]
                          [ask smalls at-points [[0 2] [-2 0] [2 0] [0 -2]] [set JSS 1.4 ]]                                         
    let joining-list (sentence (JBB) (JSS))
    let max-list max joining-list
    let min-list min joining-list
    let repellor min-one-of turtles at-points [[0 2] [-2 0] [2 0] [0 -2]]  [min joining-list] 
    let attractor max-one-of turtles at-points [[0 2] [-2 0] [2 0] [0 -2]] [ max joining-list]
    if min-list < 1
         [ set target-heading one-of [ 90 180 270 ]  + towards repellor   ;;this line has the error
           set heading target-heading]  
    if max-list > 1  
         [ face attractor] ] ;;and this line has the error
    end

海龟在点[[02][20][20][0-2]]
报告没有海龟;你必须决定在这种情况下你想做什么

您的问题可以重新解释为关于如何调试代码的问题。在本例中,您可以在每次分配任务时在代码中放置
print
show
命令,以查看实际执行的操作(如分配给
repellor
后立即执行
print repellor
)。在这种情况下,最好是
让候选人在点[[02][20][20][20][0-2][0]]上搜索海龟
,然后
打印候选人
,看看你得到的海龟集是什么


除了你的问题,还有其他一些问题。使用
minone of
max one of
的行不太可能达到您的目的。当您实际使用海龟集时,当前编写的这些行只会报告一个随机海龟。原因如下:
min其中一个
接受一个reporter参数,为此您提供了
[min加入列表]
。但这总是报告相同的数字,而不是每只海龟的不同数字。您需要将相关代码移动到一个单独的turtle reporter中,以便为turtle集合中的每个turtle重新计算值。

此外,将“turn turtle”过程改为“to report turtle heading”过程是否更好?还是没什么区别?谢谢关于添加打印语句的建议,附议。感谢关于如何调试的建议,@Alan和@SethTissue对您很有帮助!虽然玩了一段时间,我仍然没有解决这个问题。如果行“让吸引子在点[[02][20][20][20][0-2]][max list]]处最大一只海龟”只是选择一只随机海龟,我如何将其写入,以便它在扩展邻域4(在点[[02][20][20][0-2]]处为海龟分配列表中的最大J值(句子)事实上,我刚把它改为“问大人物…”,然后在转弯开始时“问小人物…”,我再也不会去了!非常感谢你的帮助。我认为我仍然需要改进上面的那一行,我的列表有时有6个条目,而它最多只能得到4个条目,所以还有一点工作要做。对上述问题有什么想法吗?谢谢我会在我的回答中详细说明。非常感谢@Alan,我更改了它,所以代码会先询问一个品种,然后询问另一个品种,它工作得非常好,再次感谢!
TOWARDS expected input to be an agent but got NOBODY instead.
error while bigs 1 running TOWARDS
  called by procedure TURN-TURTLE
  called by procedure MOVE-TURTLE
  called by procedure GO
  called by Button 'go'