Depending on the number of agents, it may be faster to have each agent assign itself to a global death-queue. Then, the simulation only needs to iterate over this smaller queue, instead of the entire list of agents.
If you have a small number of agents, though, just do the flag-and-iterate method.
From: MASON Multiagent Simulation Toolkit [mailto:[log in to unmask]] On Behalf Of Steven Pousty
Sent: Friday, September 16, 2016 2:31 PM
To: [log in to unmask]
Subject: Getting an agent to kill itself
I am trying to get an agent to "kill" itself based on some feature of the agent.
In my example it is when the agent walks "too far" over the edge of the world.
But this doesn't work. I suspect because the Agent still lives on and all I am doing is removing it from being displayed on the grid.
I have read the docs and looked at the asteroid example. It seems like I need to action kill the agent from the SimState. If this is true then it seems like I should set a flag on the agent like "dead=true" and then at the start of each step iterate through all the agents and Stop() all that are dead.
Is this correct or is there a way to "kill" an agent from within an agent? I will need to do this in the future if the animal does not eat enough or walks through too much bad habitat.
Thanks again for all the help!