当他们找到最近的领导者时,我试图让乌龟转向平均领导者的标题,但是当运行代码时,此错误消息弹出“意味着预期输入是一个列表但是获得了数字XXX而不是“这是代码:
[turn-towards average-heading-towards-leaders max-cohere-turn]
下面是我的完整代码:
to go
ask turtles [check]
tick
end
to check
if leader?
[let beings-seen patches in-cone leader-vision leader-vision-angle with [pcolor = red]
ifelse any? beings-seen
[let target one-of beings-seen
face target ]
[flock]]
end
to flock
let nearby-leaders turtles with [leader? ]
if any? nearby-leaders in-radius vision
[turn-towards average-heading-towards-leaders max-cohere-turn]
end
to-report average-heading-towards-leaders
let nearby-leaders turtles with [leader? ]
let x-component mean [sin heading] of one-of nearby-leaders
let y-component mean [cos heading] of one-of nearby-leaders
ifelse x-component = 0 and y-component = 0
[ report heading ]
[ report atan x-component y-component ]
end
有人可以指出我的代码有什么问题。谢谢你的帮助。
答案 0 :(得分:2)
问题在于这两行:
let x-component mean [sin heading] of one-of nearby-leaders
let y-component mean [cos heading] of one-of nearby-leaders
[sin heading] of one-of nearby-leaders
报告附近一位领导人的标题正弦,这是一个单一的数字。 mean
需要一份清单。所以你试图将一个数字传递给需要列表的东西。
要修复它,你可以摆脱这些行中的mean
。