Til Hund
Til Hund

Reputation: 1671

How can I count dead turtles in Netlogo

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

Upvotes: 5

Views: 3923

Answers (2)

Parth Brahmbhatt
Parth Brahmbhatt

Reputation: 41

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

Upvotes: -1

Bryan Head
Bryan Head

Reputation: 12580

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.

Upvotes: 6

Related Questions