在 NetLogo 中,如何每第 n 个刻度提取海龟子集的 x 和 y 坐标?

In NetLogo how can I extract the x and y coordinates of a subset of turtles every nth tick?

我有一个非常简单的模型,其中有 50 只海龟从一个中心点移开。我希望能够在行为 space 中每第 n 个刻度提取其中一个子集的空间坐标 (xcor, ycor)。希望你能帮忙!

模运算符 mod 可能是执行此操作的最简单方法。它输出除法运算的余数,因此您可以只使用逻辑标志,以便仅在 ticks 除以 n 等于 0 时提取坐标。例如:

to setup
  ca
  crt 10
  reset-ticks
end

to go
  ; set up lists for example output
  let tlist []
  let xlist []
  let ylist []

  ask turtles [
    rt random 60 - 30
    fd 1
  ]

  tick 

  ; If ticks is not zero, and the remainder of
  ; the number of ticks / 3 is zero, extract
  ; some info about the turtles and print it.
  if ticks > 0 and ticks mod 3 = 0 [
    ask turtles with [ xcor > 0 ] [
      set tlist lput self tlist
      set xlist lput xcor xlist
      set ylist lput ycor ylist
    ]
    print tlist
    print xlist
    print ylist
  ]  
end

运行 多次,您会看到在 tick 3(以及 6、9、12 等)上打印了列表。请注意,您的 tick 增量将影响实际提取此输出的时间 - 在上面的示例中,tick 发生在 go 过程的末尾但在评估 if 语句之前.