finish to synchronize the maze generator and the solver

This commit is contained in:
Maoake Teriierooiterai
2026-03-26 14:19:43 +01:00
parent 170de8813a
commit ef030f70a7
4 changed files with 32 additions and 29 deletions
+14 -4
View File
@@ -9,7 +9,7 @@ class MazeGenerator(ABC):
def __init__(self, start: tuple, end: tuple, perfect: bool) -> None:
self.start = (start[0] - 1, start[1] - 1)
self.end = (end[0] - 1, end[1] - 1)
self.bool = bool
self.perfect = perfect
@abstractmethod
def generator(
@@ -93,6 +93,7 @@ class MazeGenerator(ABC):
class Kruskal(MazeGenerator):
class Set:
def __init__(self, cells: list[int]) -> None:
self.cells: list[int] = cells
@@ -174,6 +175,8 @@ class Kruskal(MazeGenerator):
cells_ft = None
if height > 10 and width > 10:
cells_ft = self.get_cell_ft(width, height)
if cells_ft and (self.start in cells_ft or self.end in cells_ft):
cells_ft = None
if seed is not None:
np.random.seed(seed)
@@ -204,13 +207,20 @@ class Kruskal(MazeGenerator):
):
break
print(f"nb sets: {len(sets.sets)}")
return self.walls_to_maze(walls, height, width)
maze = self.walls_to_maze(walls, height, width)
if self.perfect is False:
gen = Kruskal.unperfect_maze(width, height, maze,
cells_ft)
for res in gen:
maze = res
yield maze
return maze
class DepthFirstSearch(MazeGenerator):
def __init__(self, start: bool, end: bool, perfect: bool) -> None:
self.start = start
self.end = end
self.start = (start[0] - 1, start[1] - 1)
self.end = (end[0] - 1, end[1] - 1)
self.perfect = perfect
self.forty_two: set | None = None
+2
View File
@@ -190,6 +190,8 @@ class DepthFirstSearchSolver(MazeSolver):
coord = self.next_cell(coord, next)
for m in move:
path_str += m
if not path:
raise Exception("Path not found")
return path_str
@staticmethod