如何在 NetLogo 中检查两只海龟是否在同一个 Y 坐标上

How to Check if the Two Turtles are on the Same Y Coordinate in NetLogo

我正在做一个 NetLogo 项目,我希望我的瞳孔海龟直线移动,直到它们与相关的 link 邻居位于相同的 Y 坐标上,然后从那里向它们移动(link 邻居).

请注意,每个学生只有一个 link 邻居。

这是我想出的代码,

to go
  ask pupils [
    let target one-of link-neighbors 
    ifelse [ycor] of myself != [ycor] of target
      [
        set heading 0
        fd 1
      ]
      [
        face target
        fd 1      
      ] 
  ]
  tick
end

这不行,海龟一直在直线前进。有人可以帮忙吗?我只想让海龟到达它们的 link 邻居,但它们必须避开墙壁。

您的问题是 ycor 是十进制值。因此,例如,海龟 1 可能在 3.2 上,而海龟 2 可能在 3.3 上。

相反,我认为您想使用 turtles-here。

to go
  ask pupils [
    let target one-of link-neighbors 
    ifelse member? target turtles-here
      [set heading 0]
      [face target] 
      fd 1
  ]
  tick
end

附带说明一下,每个目标有多少 link-neighbors?我担心的是 let target one-of link-neighbors 会在每次滴答时重置目标。