。
我有一个非常简单的50只乌龟的模型,从中心点移开。我希望能够提取行为空间中每个n tick的一个子集的空间坐标(xcor, ycor)
。希望您能提供帮助!
modulo运算符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
语句之前。