ambernetlogo
New Coder
How do I code in NetLogo that one kind of turtle is hatched if another kind of turtle dies?
The turtles in my code are 'zombies' and 'humans'. This is a part of my code in NetLogo, my intention is to code it so a zombie will be hatched when a human is killed by a zombie. How do I do this? Because now no zombies are hatched and no humans are killed. I can see that because there are no zombies added when I run the code. I also have a graph in the model that shows the human death causes and that shows that no humans are killed by zombies, they all die of age or density.
The turtles in my code are 'zombies' and 'humans'. This is a part of my code in NetLogo, my intention is to code it so a zombie will be hatched when a human is killed by a zombie. How do I do this? Because now no zombies are hatched and no humans are killed. I can see that because there are no zombies added when I run the code. I also have a graph in the model that shows the human death causes and that shows that no humans are killed by zombies, they all die of age or density.
Code:
to zombies-kill-and-infect
; zombies kill and infect humans
ask humans [
let zombies-nearby zombies in-radius 5
let r random 100
if r < 3 [ die ] ; zombies have a 3% chance of killing the human
if r < 3 + odds-of-killing - protection [
ask one-of humans-here [ die ] ; successfully killed a human!
set humans-killed-by-zombies humans-killed-by-zombies + 1
set dead-humans dead-humans + 1
ask zombies [
if humans-killed-by-zombies = 1 [ hatch 1 ]; human is killed by zombie so a zombie is born
hatch-zombies 1 [ set age 0 ]
]
]
]