乌龟仍然可以移动一些补丁,但是会出错 [英] There are still some patches that turtle can move on to but ERROR
问题描述
我要求乌龟A移动到与乌龟A具有相同乌龟类型的邻居的修补程序.它工作良好,直到出现错误(MOVE-TO预期输入是代理,但改为NOBODY)出来.视觉上仍然有一些可用的修补程序.如何编写代码,以使所有可用补丁都被占用,并在没有更多补丁要占用时报告或停止程序?任何评论将非常有帮助.我做了以下事情:
I ask a turtle A to move to patch that has a neighbor that has the same type of turtle with the turtle A. It is working well until the ERROR (MOVE-TO expected input to be an agent but got NOBODY instead) comes out. Visually there are still some available patches. How to code so that all available patches are occupied and report or stop the program when there is no more patch to occupy? Any comments will be really helpful. I did the following:
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]
ifelse target != 0 and (status != "resident") [move-to min-one-of target [value]
set status "resident"
set color blue]
[]
]
end
这是完整的代码
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]
ifelse target != 0 and (status != "resident") [move-to min-one-of target [value]
set status "resident"
set color blue]
[]
]
end
推荐答案
这一行:let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] = 1]
标识恰好有1个邻居满足这些条件的补丁.因此,具有2个这样的邻居的补丁将不可用.从您的描述中,我认为您真的想要> =而不是=:
This line: let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] = 1]
identifies the patches where there is exactly 1 neighbour meeting those conditions. So a patch with 2 such neighbours is would not be available. From your description I think you really want >= instead of =:
let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] >= 1]
这篇关于乌龟仍然可以移动一些补丁,但是会出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!