在NetLogo中,如何每隔n个刻度提取一部分海龟的x和y坐标?

时间:2017-12-19 16:48:58

标签: netlogo

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

1 个答案:

答案 0 :(得分:2)

模运算符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语句之前发生

相关问题