非常乐意向大家询问。我有一个最后的bug来压缩我的代码,然后就完成了!
我对所有这些代码的目标是,如果邻居4中有空缺补丁,则移动所有海龟。那些在他们的邻居之后的任何地方都有间隙的海龟4会在间隙之后转向或远离那只乌龟,这取决于扩展邻居的J值。所有其他海龟都搬到了邻居的另一个广场上4。
我遇到了转龟的问题。他们通常很好,除了现在,然后我得到一个错误说乌龟试图转向NOBODY。我不明白为什么会发生这种情况,因为据我所知,只有有间隙和海龟的海龟被要求转弯,所以他们应该总是有一个“有人”。转向。
世界已经结束了。我也小心翼翼地使用'检查如果我超越错误发生了什么,并且面对'也会得到同样的错误。它可能非常简单,但我无法解决这个问题。
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
运行时错误:
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'
答案 0 :(得分:1)
turtles at-points [[0 2] [-2 0] [2 0] [0 -2]]
正在报告no-turtles
;你必须决定在这种情况下你想做什么。
您的问题可能会被重新解释为有关如何调试代码的问题。在此示例中,您可以在每次进行分配时在代码中放置print
或show
命令,以便在分配给{{print repellor
后立即查看实际情况1}})。在这种情况下,最好repellor
然后let candidates turtles at-points [[0 2] [-2 0] [2 0] [0 -2]]
看看你得到了什么龟。
除了您的问题,还有其他一些问题。使用print candidates
和min-one-of
的行不太可能正在执行您的操作。每当你真正使用乌龟套装时,这些当前编写的线条只会报告一只随机乌龟。原因如下:max-one-of
采用了一个记者参数,您提供了min-one-of
。但是这总是报告相同的数字,而不是每只乌龟的数字不同。您需要将相关代码移动到单独的海龟记者中,以便为您的海龟集中的每只海龟重新计算该值。