5

I would like to know the numbers of all turtles died in my pseudo model. How can I do that? I would appreciate very much a simply and fast running solution for that problem, like count dead turtles.

I was thinking of a routine like this (but do not know how to implement it):

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

This is my code sample (without any check so far):

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
Til Hund
  • 1,543
  • 5
  • 21
  • 37

2 Answers2

6

I'm afraid you have to keep track of it yourself in a global variable. So, add

globals [ number-dead ]

to the top of your model. Then, change death like so:

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

Then number-dead will always be equal to the number of turtles that have died.

Bryan Head
  • 12,360
  • 5
  • 32
  • 50
-1

This is really simple:

to setup
 let total-population count turtles
end

to go
 let current-population count turtles
 let dead-people total-population - current-population
ticks
end
Adam
  • 5,403
  • 6
  • 31
  • 38
  • 1
    This method will not work for those methods where turtles are created after setup (eg born). The original answer will. – JenB Sep 19 '16 at 12:22