你只是給你的問題的一個非常籠統的說法。如果您努力實際開始實施並詢問您遇到的更具體的困難,您將得到更好的答案。
這就是說,我做了一個小模型,或多或少符合您的描述。也許它可能對你有用,作爲一個起點,如果你有一些問題,你可以提出單獨的(更確切的)後續問題。
turtles-own [ scope data ]
to setup
clear-all
; make a big world so agents don't
; bump into one another right away:
resize-world -100 100 -100 100
set-patch-size 3
; create turtles and distribute them around:
crt 100 [ set scope 5 set data "" ]
crt 200 [ set scope 3 set data "" ]
crt 1 [ set scope 7 set data "important data" ]
ask turtles [
set size 3
setxy random-xcor random-ycor
recolor
]
end
to go
ask turtles [ travel ]
ask turtles with [ not empty? data ] [ share-info ]
ask turtles [ recolor ]
end
to travel
; you haven't specified how turtles should move
; so here's a classic "wiggle":
rt random 30
lt random 30
fd 1
end
to share-info
ask other turtles in-radius scope with [ empty? data and distance myself < scope ] [
set data [ data ] of myself
]
end
to recolor
set color ifelse-value empty? data [ grey ] [ red ]
end
編輯:
繼賽斯的評論,我的第一個版本可能沒有捕捉共同範圍的想法,我已經添加and distance myself < scope
。這樣,只有看到彼此可以共享信息的龜。
當我問海龜分享信息時,我還增加了一個with [ not empty? data ]
條款,因爲沒有用空白數據的海龜分享它。
我不認爲這抓住了「共同的範圍」部分。如果我理解正確,A可以看到B是不夠的; B也必須能夠看到A.阿里,那是對的嗎? –
這很可能是正確的。我編輯了我的答案。 –
謝謝尼古拉斯,我正在處理你的答案,我會告訴你結果 –