Reputation: 1671
With regard to this question (NetLogo - calculate the difference of a variable of neighbouring agents), I am trying to change (for another scenario) the code so that another breed can change unilaterally the values of nearby members of the other breed (if their values are above a certain threshold) and by means of randomness can even change the value of one of (any) distant member of the other breed.
My code is (pseudo code in brackets):
breed [ greens green ]
greens-own [ variable ]
breed [ reds red ]
to setup
create-greens 100 [
set variable random 10
]
create-reds 1
end
to start
ask reds [
exchange
]
end
to exchange
rt random 360
fd 0.5
ask reds-on neighbors [
let both-turtles (turtle-set self myself)
"greens with variable > 6.9" [ set variable variable + 0.5]
]
"one-of greens [ set variable variable + 1]"
end
How can I convert the pseudo-code to NetLogo code?
Upvotes: 0
Views: 42
Reputation: 17678
any turtle can instruct any turtle to change values with ask
. you can simply state something like ask one-of greens [ set variable variable + 1]
or ask greens with [variable > 6.9][...]
. You need to take some care here, though, because you will be asking every red on a neighbour to ask ALL greens to change variable value as currently pseudo-coded.
Upvotes: 2