Skip to content

Commit

Permalink
Make the animal dies if it steps into a cliff cell
Browse files Browse the repository at this point in the history
  • Loading branch information
mgemaakbar committed Dec 23, 2024
1 parent ae0223b commit 8b3a415
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mesa/examples/advanced/wolf_sheep/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def step(self):
"""Execute one step of the animal's behavior."""
# Move to random neighboring cell
self.move()
is_cliff = self.grid.model.cliff.data[self.cell.coordinate[0]][
self.cell.coordinate[1]
]
if is_cliff: # if the cell is a cliff, then the animal dies
self.remove()
return

self.energy -= 1

Expand Down

0 comments on commit 8b3a415

Please sign in to comment.