From 03c4d206d6413fd4dd02f822a370d81932859fa5 Mon Sep 17 00:00:00 2001 From: Maoake TERIIEROOITERAI Date: Tue, 24 Mar 2026 21:21:46 +0100 Subject: [PATCH] starting the branch parsing need to get a good start on this --- a_maze_ing.py | 2 +- src/amaz_lib/MazeGenerator.py | 62 +++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/a_maze_ing.py b/a_maze_ing.py index e5f6613..59b98ac 100644 --- a/a_maze_ing.py +++ b/a_maze_ing.py @@ -7,7 +7,7 @@ import src.amaz_lib as g def main(maze_gen: MazeGenerator) -> None: # try: maze = Maze(maze=None) - for alg in maze_gen.generator(30, 10): + for alg in maze_gen.generator(30, 30): maze.set_maze(alg) os.system("clear") maze.ascii_print() diff --git a/src/amaz_lib/MazeGenerator.py b/src/amaz_lib/MazeGenerator.py index 8d4c882..56f546d 100644 --- a/src/amaz_lib/MazeGenerator.py +++ b/src/amaz_lib/MazeGenerator.py @@ -108,35 +108,38 @@ class DepthFirstSearch(MazeGenerator): def generator( self, height: int, width: int ) -> Generator[np.ndarray, None, np.ndarray]: - maze = DepthFirstSearch.init_maze(width, height) + maze = self.init_maze(width, height) visited = np.zeros((height, width), dtype=bool) path = list() w_h = (width, height) coord = (0, 0) x, y = coord - first = True + first_iteration = True + visited = self.lock_cell_ft(visited, (10, 10)) + + while path or first_iteration: + first_iteration = False - while path or first: - first = False visited[y, x] = True - path = DepthFirstSearch.add_cell_visited(coord, path) - random_c = DepthFirstSearch.random_cells(visited, coord, w_h) - if len(random_c) == 0: - path = DepthFirstSearch.back_on_step(path, w_h, visited) - if path: - coord = path[-1] - random_c = DepthFirstSearch.random_cells(visited, coord, w_h) - x, y = coord + path = self.add_cell_visited(coord, path) + + random_c = self.random_cells(visited, coord, w_h) + + if not random_c: + path = self.back_on_step(path, w_h, visited) if not path: break + coord = path[-1] + random_c = self.random_cells(visited, coord, w_h) + x, y = coord - wall = DepthFirstSearch.next_step(random_c) - maze[y][x] = DepthFirstSearch.broken_wall(maze[y][x], wall) + wall = self.next_step(random_c) + maze[y][x] = self.broken_wall(maze[y][x], wall) - coord = DepthFirstSearch.next_cell(x, y, wall) - wall_r = DepthFirstSearch.reverse_path(wall) + coord = self.next_cell(x, y, wall) + wall_r = self.reverse_path(wall) x, y = coord - maze[y][x] = DepthFirstSearch.broken_wall(maze[y][x], wall_r) + maze[y][x] = self.broken_wall(maze[y][x], wall_r) yield maze return maze @@ -194,19 +197,22 @@ class DepthFirstSearch(MazeGenerator): return (x + add_x, y + add_y) @staticmethod - def reverse_path(next: str) -> str: - reverse = {"N": "S", "S": "N", "W": "E", "E": "W"} - return reverse[next] + def reverse_path(direction: str) -> str: + return {"N": "S", "S": "N", "W": "E", "E": "W"}[direction] @staticmethod def back_on_step(path: list, w_h: tuple, visited: np.array) -> list: - last = path[-1] - r_cells = DepthFirstSearch.random_cells(visited, last, w_h) - while len(path) > 0: - path.pop() - if path: - last = path[-1] - r_cells = DepthFirstSearch.random_cells(visited, last, w_h) - if r_cells: + while path: + last = path[-1] + if DepthFirstSearch.random_cells(visited, last, w_h): break + path.pop() return path + + @staticmethod + def lock_cell_ft(visited: np.ndarray, coord: tuple) -> np.ndarray: + x, y = coord + for dy in range(y, y + 7): + for dx in range(x, x + 11): + visited[dy, dx] = True + return visited