diff --git a/a_maze_ing.py b/a_maze_ing.py index 6a82fd3..c6138f6 100644 --- a/a_maze_ing.py +++ b/a_maze_ing.py @@ -117,19 +117,24 @@ class MazeMLX: for color in colors: yield color - def update_maze(self, maze: np.ndarray) -> None: - self.clear_image() - + def get_margin_line_len(self, maze: np.ndarray) -> tuple[int, int, int]: rows = len(maze) cols = len(maze[0]) - line_len = min(self.width // cols, self.height // rows) + line_len = min(self.width // cols, self.height // rows) - 1 maze_width = cols * line_len maze_height = rows * line_len - margin_x = (self.width - maze_width) // 2 - margin_y = (self.height - maze_height) // 2 + margin_x = ((self.width - maze_width) // 2) + 1 + margin_y = ((self.height - maze_height) // 2) + 1 + + return (line_len, margin_x, margin_y) + + def update_maze(self, maze: np.ndarray) -> None: + self.clear_image() + + line_len, margin_x, margin_y = self.get_margin_line_len(maze) for y in range(len(maze)): for x in range(len(maze[0])): x0 = x * line_len + margin_x @@ -155,16 +160,7 @@ class MazeMLX: if maze is None: return - rows = len(maze) - cols = len(maze[0]) - - line_len = min(self.width // cols, self.height // rows) - - maze_width = cols * line_len - maze_height = rows * line_len - - margin_x = (self.width - maze_width) // 2 - margin_y = (self.height - maze_height) // 2 + line_len, margin_x, margin_y = self.get_margin_line_len(maze) for i in range(len(path)): ul = ( @@ -212,16 +208,7 @@ class MazeMLX: if maze is None: return - rows = len(maze) - cols = len(maze[0]) - - line_len = min(self.width // cols, self.height // rows) - - maze_width = cols * line_len - maze_height = rows * line_len - - margin_x = (self.width - maze_width) // 2 - margin_y = (self.height - maze_height) // 2 + line_len, margin_x, margin_y = self.get_margin_line_len(maze) ul = ( (entry[0] - 1) * line_len + margin_x + 3, @@ -231,30 +218,28 @@ class MazeMLX: (entry[0] - 1) * line_len + line_len + margin_x - 3, (entry[1] - 1) * line_len + line_len - 3 + margin_y, ) - # print(f"ul: {ul}; dr: {dr}") - self.put_block(ul, dr) - self.redraw_image() + self.put_block(ul, dr, [0xFF, 0xBF, 0x00, 0x9F]) + + ul = ( + (exit[0] - 1) * line_len + margin_x + 3, + (exit[1] - 1) * line_len + 3 + margin_y, + ) + dr = ( + (exit[0] - 1) * line_len + line_len + margin_x - 3, + (exit[1] - 1) * line_len + line_len - 3 + margin_y, + ) + self.put_block(ul, dr, [0x00, 0xFF, 0x40, 0x9F]) def draw_ft(self, maze: np.ndarray, color: list | None = None): - margin = math.trunc( - math.sqrt(self.width if self.width > self.height else self.height) - // 2 - ) - line_len = math.trunc( - ( - (self.height - margin) // len(maze) - if self.height > self.width - else (self.width - margin) // len(maze[0]) - ) - ) + line_len, margin_x, margin_y = self.get_margin_line_len(maze) + for y in range(len(maze)): for x in range(len(maze[0])): - x0 = x * line_len + margin - y0 = y * line_len + margin - x1 = x * line_len + line_len + margin - y1 = y * line_len + line_len + margin - if maze[y][x].value == 15: + x0 = x * line_len + margin_x + y0 = y * line_len + margin_y + x1 = x * line_len + line_len + margin_x + y1 = y * line_len + line_len + margin_y self.put_block((x0, y0), (x1, y1)) def draw_image(self, amazing: AMazeIng) -> None: @@ -292,9 +277,9 @@ class MazeMLX: try: next(self.generator) self.update_maze(amazing.maze.get_maze()) + self.put_start_end(amazing) return False except StopIteration: - self.put_start_end(amazing) pass return True @@ -341,7 +326,7 @@ class MazeMLX: def main() -> None: mlx = None try: - mlx = MazeMLX(1000, 1000) + mlx = MazeMLX(1800, 1800) config = Parsing.DataMaze.get_data_maze("config.txt") amazing = AMazeIng(**config) mlx.start(amazing) diff --git a/config.txt b/config.txt index dcd3aee..ec9b1e7 100644 --- a/config.txt +++ b/config.txt @@ -1,8 +1,8 @@ -WIDTH=11 -HEIGHT=11 +WIDTH=30 +HEIGHT=30 ENTRY=1,1 -EXIT=11,11 +EXIT=5,5 OUTPUT_FILE=maze.txt PERFECT=False -GENERATOR=DFS +GENERATOR=Kruskal SOLVER=AStar