我正在嘗試在Netlogo中編寫一個程序,該程序首先識別紅色補丁的兩個隨機鄰居,然後將這兩個補丁更改爲藍色。網格上的補丁可以是紅色,藍色或白色。Netlogo Procedure n-of 2 neighbors
我把這段代碼放在「去」部分,它使「tick」無效。它也似乎不在任何地方運行。
to run-2-neighbors-people
if all-voters-talked-2-people
[ ask n-of 2 neighbors with [ pcolor = red ]
[ set pcolor blue]
]
end
下面是完整的代碼:
patches-own
[
vote ;; my vote (0 or >= 1)
total ;; sum of votes around me
]
to setup
clear-all
ask n-of (percentage-of-voters/100 * count patches) patches [
set vote 1 ]
ask patches [set-color]
ask patches [set initial-voters count patches with [ pcolor = red ] ]
ask patches [set non-voters count patches with [pcolor = white] ]
reset-ticks
end
to go
ask patches
[ set total (sum [vote] of neighbors) ]
ask patches [if pcolor = white
[if total >= 4 [set pcolor blue ] ] ]
ask patches [if pcolor = white
[if total < 4 [ set vote 0 ] ] ]
run-all-voters-talked-2-people
run-share-on-social-media
tick
end
to run-share-on-social-media
if share-on-social-media
[ask patches with [pcolor = red] [
sprout 1 [
set shape "arrow"]
]]
end
to run-all-voters-talked-2-people
ask patches with [pcolor = red] [
ask n-of 2 neighbors with [ pcolor = red ]
[set pcolor blue] ]
end
to set-color ;; patch color procedure
ifelse vote >= 1
[ set pcolor red ]
[ set pcolor white ]
end
這是什麼「它使'剔'失效」是什麼意思? –
@SethTisue它可能意味着當他添加了這段代碼時,程序沒有打勾,這可能是因爲它沒有終止。 –
我認爲我們需要看到更多的代碼,例如「所有選民說話的2人」程序是做什麼的? –