MOVE-TO 预期输入是代理,但得到的是 NOBODY 而不是运行时错误

MOVE-TO expected input to be an agent but got NOBODY instead runtime error

当我尝试在它们拥有的 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

我希望这能奏效,因为移动到其中一个补丁命令似乎非常简单。

因此,move-to one-of patches 是一个非常安全的命令,当 运行 在 turtle 上下文中时,它永远不会失败。

但是你正在做一些更复杂的事情:

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个补丁的代理集。 one-of 一个空的代理集会给你 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...
]

请注意,根据您编写的代码,所有 "farms" 看起来很容易被带走并且没有留下合适的空地,具体取决于您有多少海龟。