I've been tasked with a question of "randomly selecting a neighbour patch that has a higher elevation." My code is found below.
I believe I am required to use the "any?" command to prevent getting the 'nobody' issue.
to move-up
let myelevPatch [elevation] of patch-here
let higherpatches neighbors with [elevation > myelevPatch]
move-to one-of higherpatches
end
I can't seem to get around this problem, if you could help me get around it, it is very much appreciated
Your code seems to be right other than the nobody case. Any? consumes a agentset. neighbors with returns an agentset.
to move-up
let myelev [elevation] of patch-here
let higherpatches neighbors with [elevation > myelev]
if any? higherpatches
[move-to one-of higherpatches]
end
Note the following is equivalent:
if count higherpatches > 0