我打算做的是让一群代理人从全世界的巢中涌出来。
我正在使用植绒代码,我有问题确定朝向凝固部分。由于所有代理都从巢中移动,我该如何设置其标题?
编辑代码后出现的错误是:
No heading is defined from a point (0,0) to that same point.
error while turtle 1 running TOWARDS
called by procedure AVERAGE-HEADING-TOWARDS-FLOCKMATES
called by procedure COHERE
called by procedure FLOCK
以下是agentset的代码:
to setup
clear-all
let number-of-groups 3
let turtles-per-group 4
create-turtles turtles-per-group * number-of-groups
[ set color red
set size 1.5
set pen-mode "down"
]
set groups [] ; empty list
repeat number-of-groups [
let new-group n-of turtles-per-group turtles with [
not is-agentset? my-group
]
ask new-group [ set my-group new-group ]
set groups lput new-group groups
]
reset-ticks
end
to go
ask turtles [flock]
end
这是植绒部分
to flock
find-flockmates
if any? flockmates
[
find-nearest-neighbor
ifelse distance nearest-neighbor < minimum-separation
[ separate ]
[ align
cohere ] ]
end
to find-flockmates ;; turtle procedure
set flockmates my-group
end
to find-nearest-neighbor ;; turtle procedure
set nearest-neighbor min-one-of flockmates [distance myself]
end
;;; COHERE
to cohere
turn-towards average-heading-towards-flockmates max-cohere-turn
end
to-report average-heading-towards-flockmates
let x-component mean [sin (towards myself + 180)] of flockmates
let y-component mean [cos (towards myself + 180)] of flockmates
ifelse x-component = 0 and y-component = 0
[ report heading ]
[ report atan x-component y-component ]
end
我在更改to-report average-heading-towards-flockmates
的代码时遇到问题,因为towards myself + 180)] of flockmates
无法在此处使用。任何人都可以帮助我吗?