diff --git a/mesa/agent.py b/mesa/agent.py index 2f0e842d382..7ec94196bea 100644 --- a/mesa/agent.py +++ b/mesa/agent.py @@ -48,6 +48,7 @@ def __init__(self, unique_id: int, model: Model) -> None: self.unique_id = unique_id self.model = model self.pos: Position | None = None + self.heading = 90 # register agent try: @@ -75,6 +76,20 @@ def step(self) -> None: def advance(self) -> None: pass + def die(self): + """Removes the agent from the schedule and the grid """ + try: + self.model.schedule.remove(self) + except Exception as exc: + warnings.warn(f"agent.py (die): could not remove agent {self.id} " + f"from self.model.schedule. Not removing from space.\n{exc}") + return + try: + self.model.space.remove_agent(self) + except Exception as exc: + warnings.warn(f"agent.py (die): could not remove agent {self.id} " + . f"from self.model.space.\n{exc}") + @property def random(self) -> Random: return self.model.random