I tried to move a turtle to a patch where there 2 turtles with the same type (e.g income) as its neighbor and stay there. I did the following code
to set-move
let target []
ask turtles with [income = "low"]
[ let potential-target1 patches with [value < buymiddle and any? turtles-here = false]
set target potential-target1 with [length remove-duplicates [any? turtles-here with [income = "low"]] of neighbors = 2]
set target min-one-of potential-target1 [value]
if target != nobody and any? turtles-on neighbors
[ move-to target ask patch-here [set empty false]]]
but it seems did not work. Some turtles still move around after choosing a patch. Some turtles do not choose a patch where there two neighbors of its group. How to specify a patch with two neighbors of certain groups of turtles?
breed [agens agen]
patches-own [value
empty]
turtles-own [income
myHouses
]
to setup
ca
;;Check inputs
let total-prob prob-low + prob-mid + prob-high
if (total-prob != 100 )
[
print (word "Adoption types must sum to 100, but instead sum to " total-prob)
stop
]
ask patches [set value random-normal 10 3]
ask patches [ifelse (value < 8)[ set pcolor green ]
[ifelse (value < 11)[ set pcolor blue]
[if value < 15[ set pcolor gray]]]]
end
to go
ask patches [
if random 100 < 3 [sprout-agens 1 [set color red
set shape "default"
set size 1
set-income
set-move]]]
end
to set-move
let target []
ask turtles with [income = "low"]
[ let potential-target1 patches with [value < buymiddle and any? turtles-here = false]
set target potential-target1 with [length remove-duplicates [any? turtles-here with [income = "low"]] of neighbors = 2]
set target min-one-of potential-target1 [value]
if target != nobody and any? turtles-on neighbors
[ move-to target ask patch-here [set empty false]]]
ask turtles with [income = "middle"]
[ let potential-target2 patches with [(value > buymiddle and value < buyhigh) and any? turtles-here = false]
let target2 potential-target2 with [length remove-duplicates [any? turtles-here with [income = "middle"]] of neighbors = 2]
set target2 min-one-of potential-target2 [value]
if target2 != nobody and any? turtles-on neighbors
[ move-to target2 ask patch-here [set empty false]]]
ask turtles with [income = "high"]
[ let potential-target3 patches with [(value > buyhigh) and any? turtles-here = false]
let target3 potential-target3 with [length remove-duplicates [any? turtles-here with [income = "high"]] of neighbors = 2]
set target3 min-one-of potential-target3 [value]
if target3 != nobody and any? turtles-on neighbors
[ move-to target ask patch-here [set empty false]]]
end
to set-income
let kind-prob (random 100)
let cumulative-prob prob-low
ifelse (kind-prob < cumulative-prob)[set income "low" set color red]
[set cumulative-prob cumulative-prob + prob-mid
ifelse (kind-prob < cumulative-prob)[set income "middle" set color pink ]
[set cumulative-prob cumulative-prob + prob-high
if income < cumulative-prob [set income "high" set color blue]
]]
end