Netlogo:两个具有相同代码的文件:一个有效,另一个标记错误

Netlogo: two files that have same code: one works, the other marks error

我有两个具有相同代码的 netlogo 文件:

to setup
  ca
  crt 10
  [setxy random-xcor random-ycor]
  reset-ticks
end

to go
    ask turtles [
    ifelse any? turtles-on patch-ahead 1
    [rt random 40 lt random 40]
    [fd 1]]
  tick
end

在这个文件中工作:test 1, 但不是这个:test 2。它指出

TURTLES-ON expected input to be an agent or agentset but got NOBODY instead.

为什么会这样? 错误代码是一个较大模型的一部分,该模型指出了相同的错误,我该如何解决?

此问题是由于您的两个文件中的世界环绕不同 - 在测试 1 中您有世界环绕:

而您在测试 2 中将其关闭:

这意味着任何到达世界边缘的海龟都在查询一个不存在的补丁——一个在世界之外的补丁 (nobody)。您可以打开世界环绕,或者通过使用 can-move? 之类的东西或通过手动编码来检查运动是否可能来解决运动模型。例如,您可以将 test 2 中的 go 更改为

to go
    ask turtles [
    ifelse patch-ahead 1 = nobody or any? turtles-on patch-ahead 1
    [rt random 40 lt random 40]
    [fd 1]
  ]
  tick
end

请注意,在这种情况下顺序很重要 - 您必须在检查 any? turtles-on patch-ahead 1

之前检查 nobody