I am trying to write a procedure in Netlogo that first identifies two random neighbors of a red patch, and then changes the two patches to blue. The patches on the grid are either red, blue or white.
I put this code in the "to go" section and it invalidated the "tick". It also doesn't seem to run anywhere.
to run-2-neighbors-people
if all-voters-talked-2-people
[ ask n-of 2 neighbors with [ pcolor = red ]
[ set pcolor blue]
]
end
Here is the complete code:
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