new users cannot
but I copy and paste here the code:
now the check is fine but when I click go another error appear…
globals [
D ; distance in patches (e.g., 10 for 1 km)
]
patches-own [
land-use ; “green”, “building”, or “centrality”
]
to setup
clear-all
set D 10 ; you can replace this with a slider if preferred
; Initialize all patches as green
ask patches [
set land-use “green”
set pcolor green
]
; Set the central patch as centrality (white)
let center patch 0 0
ask center [
set land-use “centrality”
set pcolor white
]
; Set one adjacent patch as building (black)
ask patches [
; Set one adjacent patch as building (black)
let adjacent-patch one-of neighbors4 with [land-use = “green”]
ask adjacent-patch [
set land-use “building”
set pcolor black
]
]
end
to go
; Try to find a new valid patch for building
let candidate-patches patches with [
land-use = “green” and
any? patches with [land-use = “centrality” and distance myself <= D] and
any? patches with [land-use = “green” and distance myself <= D] and
any? neighbors4 with [land-use = “building”]
]
; Ensure all green patches are adjacent to at least one other green
set candidate-patches candidate-patches with [
count neighbors4 with [land-use = “green”] > 0
]
; If at least one valid patch, add a building
if any? candidate-patches [
ask one-of candidate-patches [
set land-use “building”
set pcolor black
]
]
; If no valid patch and some building is too far from all centralities → add a new centrality
if not any? candidate-patches [
let buildings patches with [land-use = “building”]
let centralities patches with [land-use = “centrality”]
; Find the building farthest from any centrality
let max-distance 0
let farthest-building nobody
foreach sort buildings [
b ->
let min-dist min [distance b] of centralities
if min-dist > max-distance [
set max-distance min-dist
set farthest-building b
]
]
; If the farthest building is beyond D, add a centrality at distance D from it
if max-distance > D [
let dir random-float 360
let new-x round ([pxcor] of farthest-building + D * cos dir)
let new-y round ([pxcor] of farthest-building + D * sin dir)
if patch new-x new-y != nobody and [land-use] of patch new-x new-y = "green" [
ask patch new-x new-y [
set land-use "centrality"
set pcolor white
]
]
]
]
; If still no patch can be added, stop
if not any? patches with [
land-use = “green” and
any? patches with [land-use = “centrality” and distance myself <= D] and
any? patches with [land-use = “green” and distance myself <= D] and
any? neighbors4 with [land-use = “building”] and
count neighbors4 with [land-use = “green”] > 0
] [
stop
]
tick
end