Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions mesa/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down