Netlogo:如何同时指定 ID 最小的乌龟和 ID 第二小的乌龟?

Netlogo: How can I specify the turtle of the smallest ID and the turtle of the second smallest ID both?

如何同时指定ID最小的乌龟和ID次小的乌龟?下面是一个示例程序,但效果不佳。特别是 "ask min - one - of turtles [who + 1]" 我认为这个语法可能是错误的,但我不太理解。还有其他方法吗?我可能需要你的建议。谢谢。

globals [ nb-white nb-red ]

to setup
  clear-all
  reset-ticks
end

to go

  ask patch 0 0 [sprout 1]
  ask min-one-of turtles [who] [set color white]   
  ask min-one-of turtles [who + 1] [set color red]

  ask (turtles-on patch 0 0) [
    set nb-white count turtles-here with [color = white]
    set nb-red count turtles-here with [color = red]
  ]

end

使用 [who + 1] 作为报告者将使每只乌龟报告其 who 数字加一 - 因此 who 为 0 的乌龟将报告 1,[=13] 的乌龟将报告=] of 1 将报告 2,依此类推 - 所以 min-one-of 乌龟不会改变。

如果您必须使用who号码,不建议这样做,您可以尝试:

globals [ nb-white nb-red ]

to setup
  clear-all

  crt 2
  ask first sort turtles [ set color white ] 
  ask item 1 sort turtles [ set color red ]

  set nb-white count turtles with [color = white]
  set nb-red count turtles with [color = red]

  reset-ticks
end

sort turtles returns 一个升序排列的代理列表- first 将 return 具有最低 who 的海龟(与 min-one-of turtles [who]), item 1倒数第二。

编辑:

globals [ nb-white nb-red ]

to setup
  clear-all
  reset-ticks
end

to go
  ask patch 0 0 [sprout 1]
  ask first sort turtles [ set color white ] 
  if count turtles > 1 [
    ask item 1 sort turtles [ set color red ]
  ]

  set nb-white count turtles with [color = white]
  set nb-red count turtles with [color = red]
end

重申(正如 Nicolas 所说)您绝对应该考虑是否真的需要为此使用 who 数字 - 通常不需要,这不是很好的做法,并且可能会导致问题。