I want to make turtles move around and look for a partner (a turtle that is not already partnered that is on the same patch) , and when they found one I want them to hatch a certain number of turtles and then die. But what happens is that when I start the simulation, all turtles die at the first tick. What am I doing wrong?
to go
ask turtles [
partner-up
]
birth
death
tick
end
to partner-up
if (not partnered?) [
rt (random-float 90 - random-float 90) fd 1
set partner one-of (turtles-at 0 0) with [ not partnered? ]
if partner != nobody [
set partnered? true
ask partner [
set partnered? true
set partner myself
]
]
]
end
to birth
let partnered-turtles turtles with [ partnered? ]
ask partnered-turtles [
calculate-score
hatch (score + 1)
]
end
to death
let partnered-turtles turtles with [ partnered? ]
ask partnered-turtles [
die
]
end
Two things stand out- one is the call to
one-of (turtles-at 0 0) with [ not partnered? ]. This includes ALL turtles on the patch that you indicate (equivalent toturtles-here), which means including the turtle executing the command. I think you wantother turtles-hereor(other turtles-at 0 0).Next, your 'baby turtles' are inheriting all the attributes of their parents, including values in their
partnered?andpartnervariables. So, the turtles are being hatched withpartnered? = true, and so when the call todeathoccurs in yourgoprocedure, they qualify aspartnered-turtlesand therefore die. To correct this, you can explicitly set the variables for your hatched turtles- for example:Also, not sure if this is intentional but wanted to point out that both 'partners' will
hatchan offspring. If you want a more standard biological model you may want only one of the parents to hatch.Revised toy model: