Netlogo Logic

Sequential Logic

The reason only one turtle dies when you use the die command within a procedure like this is that the logic is being executed by each turtle independently, rather than as a collective decision by all turtles on the same patch.

Here’s what’s happening in your code:

  1. Independent Execution: Each turtle checks if there are two turtles on the current patch (count turtles-here = 2). When this condition is true for a turtle, it performs the actions specified in the block.

  2. Immediate Effect of die: When a turtle calls die, it immediately removes itself from the simulation. Other turtles on the patch don’t get a chance to execute the same die command within the current meet cycle because the logic breaks for other turtles on the patch once a turtle dies and the count of turtles is no longer two.

  3. Sequential Action: If two turtles are on the same patch and one is selected first by the NetLogo scheduler to check the condition, it will execute the die command and reduce the turtle count, leading to the other turtle not meeting the condition anymore.

To have both turtles potentially die when they meet on the same patch, you can use a different approach. One way is to mark turtles for death and then process the actual removal later. Here’s a conceptual approach to handling this:

Using a Mark-and-Clean Approach

  1. Add a New Turtle Variable: Add a flag variable to mark turtles for deletion.

  2. Mark Turtles Instead of Immediately Dying:

    Modify your meeting code:

  3. Remove Marked Turtles in a Separate Procedure:

    Create a procedure that removes turtles marked for death:

  4. Call cleanup at Each Tick: Add a call to cleanup in your go procedure or main loop.

This approach separates the marking of turtles for death and their actual removal, ensuring that multiple turtles on the same patch can be marked before any are removed, leading to potentially multiple turtles being removed after they meet.