当没有更多的补丁可以占用时打印 "no patch"
Print "no patch" when there is no more patches to occupy
我想在没有更多补丁可占用时打印 "no path",而不是收到错误 "MOVE-TO expected input to be an agent but got NOBODY instead." 警告。我做了几件事,但没有奏效。最后,我做了以下事情;
ask migrants
[let pot-target patches with [value < 11 and not any? turtles-here]
let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] >= 1]
if target = 0 [print (word "no patch")]
if (target != 0 and (status != "resident")) [move-to min-one-of target [value]
set status "resident"
set color blue]
]
这里是完整的代码
breed [migrants migrant]
breed [residents resident]
patches-own [value]
turtles-own [income
status]
to setup
ca
let total problo + probmid + probhi
if (total != 100)
[print (word "prob is more than 100")]
ask patches [set value random-normal 10 3
let patch-value value
set pcolor scale-color (gray - 5) patch-value 10 3]
ask patches
[if random 100 < 3
[sprout-residents 1
[set color red
set shape "default"
set size 1
set status "resident"
]
]
]
end
to go
ask patches
[if random 100 < 1
[sprout-migrants 1
[set color green
set shape "default"
set size 1
set status "migrant"
set-move
]]]
end
to set-move
ask migrants
[let pot-target patches with [value < 11 and not any? turtles-here]
let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] >= 1]
if target = 0 [print (word "no patch")]
if (target != 0 and (status != "resident")) [move-to min-one-of target [value]
set status "resident"
set color blue]
]
end
您混淆了一个代理集和该代理集中的 count
个代理。这一行:
let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] >= 1]
returns 一个代理集。所以你的变量"target"就是所有符合你条件的补丁。如果没有满足你条件的patch,那么agentset不是0,而是agentset的count
是
因此您需要将 if target = 0 [print (word "no patch")]
替换为 if count target = 0 [print (word "no patch")]
或 if not any? [print (word "no patch")]
。
我想在没有更多补丁可占用时打印 "no path",而不是收到错误 "MOVE-TO expected input to be an agent but got NOBODY instead." 警告。我做了几件事,但没有奏效。最后,我做了以下事情;
ask migrants
[let pot-target patches with [value < 11 and not any? turtles-here]
let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] >= 1]
if target = 0 [print (word "no patch")]
if (target != 0 and (status != "resident")) [move-to min-one-of target [value]
set status "resident"
set color blue]
]
这里是完整的代码
breed [migrants migrant]
breed [residents resident]
patches-own [value]
turtles-own [income
status]
to setup
ca
let total problo + probmid + probhi
if (total != 100)
[print (word "prob is more than 100")]
ask patches [set value random-normal 10 3
let patch-value value
set pcolor scale-color (gray - 5) patch-value 10 3]
ask patches
[if random 100 < 3
[sprout-residents 1
[set color red
set shape "default"
set size 1
set status "resident"
]
]
]
end
to go
ask patches
[if random 100 < 1
[sprout-migrants 1
[set color green
set shape "default"
set size 1
set status "migrant"
set-move
]]]
end
to set-move
ask migrants
[let pot-target patches with [value < 11 and not any? turtles-here]
let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] >= 1]
if target = 0 [print (word "no patch")]
if (target != 0 and (status != "resident")) [move-to min-one-of target [value]
set status "resident"
set color blue]
]
end
您混淆了一个代理集和该代理集中的 count
个代理。这一行:
let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] >= 1]
returns 一个代理集。所以你的变量"target"就是所有符合你条件的补丁。如果没有满足你条件的patch,那么agentset不是0,而是agentset的count
是
因此您需要将 if target = 0 [print (word "no patch")]
替换为 if count target = 0 [print (word "no patch")]
或 if not any? [print (word "no patch")]
。