Skip to content

Commit

Permalink
Fix is_trapped_in_wall
Browse files Browse the repository at this point in the history
  • Loading branch information
mgemaakbar committed Jan 3, 2025
1 parent 8216153 commit 98fc94c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion mesa/examples/advanced/wolf_sheep/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def is_trapped_in_wall(
): # true if cell is trapped of walls
north = (cell.coordinate[0] - 1, cell.coordinate[1])
south = (cell.coordinate[0] + 1, cell.coordinate[1])
west = (cell.coordinate[0], cell.coordinate[1] - 1)
east = (cell.coordinate[0], cell.coordinate[1] + 1)
west = (cell.coordinate[0], cell.coordinate[1] - 1)

coord = (cell.coordinate[0], cell.coordinate[1])

Expand All @@ -41,6 +41,14 @@ def is_trapped_in_wall(
return {west, south}.issubset(wall_coord)
if coord == (height - 1, width - 1): # bottom right corner
return {north, west}.issubset(wall_coord)
if coord[0] == 0: # for cells at top row
return {south, west, east}.issubset(wall_coord)
if coord[1] == 0: # for cells at leftmost column
return {north, south, east}.issubset(wall_coord)
if coord[0] == height - 1: # for cells at the bottom row
return {north, east, west}.issubset(wall_coord)
if coord[1] == width - 1: # for cells at rightmost column
return {north, south, west}.issubset(wall_coord)

return {north, south, west, east}.issubset(wall_coord)

Expand Down

0 comments on commit 98fc94c

Please sign in to comment.