我如何计算Netlogo中的死龟

时间:2014-12-08 14:40:43

标签: 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

2 个答案:

答案 0 :(得分:5)

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

globals [ number-dead ]

到模型的顶部。然后,像这样更改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

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

答案 1 :(得分:0)

这很简单:

to setup
 let total-population count turtles
end

to go
 let current-population count turtles
 let dead-people total-population - current-population
ticks
end
相关问题