Skip to content

Commit 5dcca08

Browse files
Add assertion for maze constraints and limit _random_floor_cell attempts (#515)
* Added assertion and infinite loop fix for maze environment * Fixed maze grid size validation formula * Removed assertion check due not working for all maze configurations
1 parent 7d68a6c commit 5dcca08

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

reasoning_gym/games/maze.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,12 @@ def _generate_random_maze(self, rng: random.Random, size: int) -> list[list[str]
152152
def _random_floor_cell(self, rng: random.Random, grid: list[list[str]]) -> tuple[int, int]:
153153
"""Pick a random path cell inside the maze (not the border)."""
154154
size = len(grid)
155-
while True:
155+
for _ in range(self.num_retries):
156156
r = rng.randint(1, size - 2)
157157
c = rng.randint(1, size - 2)
158158
if grid[r][c] == self.path_char:
159159
return (r, c)
160+
raise RuntimeError(f"Could not find suitable path cell after {self.num_retries} attempts")
160161

161162
def _bfs_shortest_path(
162163
self, grid: list[list[str]], start_r: int, start_c: int, goal_r: int, goal_c: int

0 commit comments

Comments
 (0)