Raj
Raj

Reputation: 1071

How to track a new born turtle in netlogo

In the model that i have developed, turtles are born if a certain condition is met. When a new turtle is born, I want to track it i.e. if there are already 3 turtles alive and a 4th is born, i want to know which turtle was the newly-born.

Initially the system starts out with 2 turtles. So if a new turtle is born i first want to know that and then i want to track that turtle in terms of either WHO number or if there is a better way to do it.

To find if a new turtle is born, i initially thought of keeping count of the turtles in the previous tick and the current tick but since turtles can also die in my model the birth of a new party wont register if turtle birth and death happens simultaneously.

Upvotes: 1

Views: 162

Answers (1)

Alan
Alan

Reputation: 9620

See if this responds to your need:

to illustrate
  ca
  crt 2
  print [who] of turtles
  print-youngest
  ask turtles [hatch 1]
  print-youngest
  ask turtle who-of-youngest [die]
  print-youngest
end

to-report who-of-youngest
  report last sort [who] of turtles
end

to print-youngest
  print (word "turtle " who-of-youngest " is youngest.")
end

Upvotes: 2

Related Questions