我如何计算Netlogo中的死龟

Til*_*und 4 netlogo

我想知道在我的伪模型中死亡的所有海龟的数量.我怎样才能做到这一点?我非常感谢这个问题的简单快速运行解决方案,比如count dead turtles.

我在考虑这样的例程(但不知道如何实现它):

if turtle is dead % checking all turtles if dead or alive set death_count death_count + 1 % set counter tick % go one step ahead in model

这是我的代码示例(到目前为止没有任何检查):

breed [ humans human ]
humans-own [ age ]

to setup
  ca

  create-humans(random 100)
  [
    setxy random-xcor random-ycor
    set age (random 51)
  ]

  reset-ticks
end

to death
  ask humans [
     if floor (ticks mod 1) = 0 [
       set age age + 1 ]
     if age > 85 [ die ]
  ]
end

to go
  death
  tick
  if ticks > 20 [ stop ]
end
Run Code Online (Sandbox Code Playgroud)

Bry*_*ead 5

我担心你必须在一个全局变量中自己跟踪它.所以,添加

globals [ number-dead ]
Run Code Online (Sandbox Code Playgroud)

到你的模型的顶部.然后,改变death如下:

to death
  ask humans [
     if floor (ticks mod 1) = 0 [
       set age age + 1 ]
     if age > 85 [
       set number-dead number-dead + 1
       die
     ]
  ]
end
Run Code Online (Sandbox Code Playgroud)

然后number-dead将始终等于死亡的海龟数量.