如何获得一个补丁来计算通过它的海龟

How to get a patch to count the turtles passing through it

我想让补丁计算站在上面的海龟的数量。理想的情况是这样的事件:

if turtle-lands-on-me [add one to count]

因为海龟可以离开并返回并被计算两次(这是我想要的)并且它可以避免计算静止不动两次或更多次的海龟(我不想要)。有什么办法可以实现吗?

谢谢!

你需要的是每个补丁的变量(我在下面称之为 'landed')。下面的代码假设您想了解它在每个时间步上落下的补丁,但忽略它经过的补丁。它还会根据请求仅在乌龟更改补丁的地方更新计数,并用计数标记补丁。

patches-own [landed]

to setup
  create-turtles 20
  [ setxy random-xcor random-ycor
  ]
end

to go
  ask turtles
  [ let old-patch patch-here
    set heading random 360
    forward one-of [0 0.5 1 3]
    if old-patch != patch-here
    [ ask patch-here
      [ set landed landed + 1
      ]
    ]
  ]
  ask patches [set plabel landed]
end

问题是一只海龟可以在一个时间步内通过多个补丁。你可以在那些移动 3 的海龟的示例模型中看到这一点。如果你也想要它们,你需要做一些类似于 NetLogo 模型库中的 'Line of Sight' 模型的事情。