我是 netlogo 的新手,并且一直在结合派系模型和遵循/避免模型的代码。
我已经将我的海龟分成派系(显示为不同的颜色),我试图让它们跟随它们上方的派系,并避免它们下方的派系。如果有人可以看看我的代码会很棒,我认为它不起作用,因为我试图使用“品种”来区分海龟在他们之上/之下的判断,并且所有海龟都需要不同。我已经把我认为不允许它工作的区域以粗体显示..
breed [ above ]
breed [ below ]
turtles-own
[ faction ]
to setup
clear-all
ask patches [ set pcolor white ]
set-patch-size 10
resize-world min-pxcor max-pxcor min-pycor max-pycor
ask patch 0 0
[ ask patches in-radius ( max-pxcor * .9) with [ random-float 100 < density ]
[ sprout 1
[
set shape "circle"
set faction random factions
set color faction-color
set size 1.1
judge
] ] ]
reset-ticks
end
to go
ask turtles [ avoid ]
ask turtles
[ fd 0.1
if any? above in-radius 360; vision in patches and degrees
[ set heading (towards min-one-of above [distance myself]) ] ]; adjusts heading to point towards
ask turtles
[ fd 0.1
if any? below in-radius 360; vision in patches and degrees
[ set heading (towards min-one-of below [distance myself]) + 180 ] ] ; adjusts heading to point away from wanderer
tick
end
to judge
if turtle color = faction-color + 30
[ set breed above ]
if turtle color = faction-color
[ set breed same ]
if turtle color = faction-color - 30
[ set breed below ]
end
;; EXTRAS
to avoid
ifelse not any? other turtles-on patch-ahead 1
[ fd 0.1 ]
[ rt random 360 ]
end
to-report faction-color
report red + faction * 30
end
如果有人能指出我正确的方向,那就太好了。再次感谢。