2014-02-17 33 views
3

我想用NetLogo在移動公告板上模擬公告的顏色。我可以讓bulleting在相遇時改變顏色,但顏色的變化是隨機的,有時候相同顏色的公告會在我的範圍內觸摸或靠近在一起我希望公告中的某個特定顏色raduis.Here是我的代碼的一小部分。任何人都可以幫我解決問題嗎?用NetLogo代理着色

to color-bulletins 
    ask bulletins [ 
    ask other bulletins in-radius 2[ 
     ask one-of bulletins [ set color green] 
     ask one-of bulletins [ set color white ] 
     ask one-of bulletins [ set color yellow] 
     ask one-of bulletins [ set color blue ] 
    ]] 
end 

回答

3

下面是做到這一點的一種方法:

breed [ bulletins bulletin ] 

to setup 
    ca 
    create-bulletins 1000 [ setxy random-xcor random-ycor ] 
end 

to color-bulletins 
    ask bulletins [ 
    let used-colors [ color ] of other bulletins in-radius 2 
    let available-colors filter [ not member? ? used-colors ] base-colors 
    set color ifelse-value (length available-colors > 0) 
     [ one-of available-colors ] 
     [ one-of base-colors ] 
    ] 
end 

這是假設你只想要使用base-colors,他們可以全部已被使用,在這種情況下,你仍然會得到一個「色彩碰撞」,但你無能爲力。除非您的代理人的空間分佈相當密集,難以實施,否則不應該經常發生。