当我尝试在它们拥有的radius中的单独补丁组上创建代理时,我得到一个运行时错误。
我在这里寻找答案,但我不能完全理解它们。如果有的话,使用吗?是人们经常做的事情。我如何在这里实现它,或者我还能做什么?
to set-farm-in-radius [d]
move-to one-of patches with [not any? other patches in-radius d with
[belongs-to != nobody]]
set farm patches in-radius farm-size
ask farm [set belongs-to myself]
let c random 6 + 61
ask farm [set pcolor c]
end我预计这会起作用,因为移动到一个补丁命令似乎真的很容易。
发布于 2019-04-10 22:18:53
因此,move-to one-of patches是一个非常安全的命令,在海龟上下文中运行时它应该永远不会失败。
但是你正在做一些更复杂的事情:
move-to one-of patches with [not any? other patches in-radius d with [belongs-to != nobody]]所以patches with [not any? other patches in-radius d with [belongs-to != nobody]]可以给出一个包含0个补丁的代理集。一个空的代理集将为您提供nobody。
因此,像这样的方法可能会更有效:
let open-patches patches with [not any? other patches in-radius d with [belongs-to != nobody]]
ifelse (any? open-patches) [
move-to one-of open-patches
set farm patches in-radius farm-size
ask farm [set belongs-to myself]
let c random 6 + 61
ask farm [set pcolor c]
] [
; handle the case where there are no open patches...
]请注意,根据您编写的代码,所有“农场”看起来都很容易被占用,并且没有留下合适的空地,这取决于您有多少只乌龟。
https://stackoverflow.com/questions/55614260
复制相似问题