I am working on a model to simulate the development model. Now, there is a tricky problem returned in my codes:
to develop
grow-population
ask patches with [pcolor = grey][ask neighbors [set potential (potential + one-of [1 -1])]]
ask patches [ set new-potential (potential + sum [potential] of neighbors4) / 5 + one-of [1 -1] ]
ask patches [ set potential new-potential
set development_patch patches with
[potential > threshold and urban? = 0 and fitness = 1 and population > 5]
if any? development_patch
[let selected_patch one-of development_patch
ask selected_patch [set urban? 1
set land-use "Urban"
set pcolor blue
]
]
]
tick
end
I randomly chose one of the item to run, but the result shows it runs a bunch of items. So, how should I just let one of the patches (selected_patch) change color in each tick? Thanks.
Your issue stems from selecting your item inside a ask patches[...]
call. This means that every single patch selects a patch that has to be turned blue. Moving the statement outside of the brackets fixes your issue
ask patches [
set potential new-potential
set development_patch patches with [potential > threshold and urban? = 0 and fitness = 1 and population > 5]
]
if any? development_patch [
let selected_patch one-of development_patch
ask selected_patch [
set urban? 1
set land-use "Urban"
set pcolor blue
]
]