【发布时间】:2020-03-02 11:31:00
【问题描述】:
我试图将一只乌龟移动到一块有 2 只与它的邻居具有相同类型(例如收入)的乌龟的地方并留在那里。我做了以下代码
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]]]
但它似乎不起作用。一些海龟在选择了一个补丁后仍然会四处走动。有些海龟不会选择一个有两个邻居的补丁。 如何指定具有某些海龟组的两个邻居的补丁?
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
【问题讨论】:
标签: netlogo move neighbours