3 Commits

Author SHA1 Message Date
Maoake Teriierooiterai 68d710e313 color 42 2026-03-29 18:47:29 +02:00
Maoake Teriierooiterai b682274102 opti path 2026-03-29 14:31:04 +02:00
mteriier d534993f4c starting my branch need to rush this 2026-03-28 23:01:42 +01:00
3 changed files with 49 additions and 6 deletions
+37 -1
View File
@@ -1,4 +1,4 @@
from typing import Any, Generator from typing import Any
from src.AMazeIng import AMazeIng from src.AMazeIng import AMazeIng
from src.parsing import Parsing from src.parsing import Parsing
from mlx import Mlx from mlx import Mlx
@@ -116,6 +116,7 @@ class MazeMLX:
) )
) )
self.update_maze(maze) self.update_maze(maze)
self.color_ft(maze)
for i in range(len(path)): for i in range(len(path)):
ul = ( ul = (
(actual[0]) * cell_size + margin + 12, (actual[0]) * cell_size + margin + 12,
@@ -157,6 +158,38 @@ class MazeMLX:
self.redraw_image() self.redraw_image()
return return
def color_ft(self, maze: np.ndarray):
self.clear_image()
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])
)
)
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].get_north():
self.put_line((x0, y0), (x1, y0))
if maze[y][x].get_est():
self.put_line((x1, y0), (x1, y1))
if maze[y][x].get_south():
self.put_line((x0, y1), (x1, y1))
if maze[y][x].get_west():
self.put_line((x0, y0), (x0, y1))
if maze[y][x].value == 15:
self.put_block((x0, y0), (x1, y1))
self.redraw_image()
def close_loop(self, _: Any): def close_loop(self, _: Any):
self.mlx.mlx_loop_exit(self.mlx_ptr) self.mlx.mlx_loop_exit(self.mlx_ptr)
@@ -198,8 +231,11 @@ class MazeMLX:
self.update_maze(amazing.maze.get_maze()) self.update_maze(amazing.maze.get_maze())
# time.sleep(0.01) # time.sleep(0.01)
except StopIteration: except StopIteration:
# self.color_ft(amazing)
if self.path_printer is not None: if self.path_printer is not None:
self.render_path() self.render_path()
else:
self.color_ft(amazing.maze.get_maze())
def main() -> None: def main() -> None:
+5 -5
View File
@@ -1,8 +1,8 @@
WIDTH=11 WIDTH=50
HEIGHT=11 HEIGHT=50
ENTRY=1,1 ENTRY=1,1
EXIT=11,11 EXIT=11,11
OUTPUT_FILE=maze.txt OUTPUT_FILE=maze.txt
PERFECT=True PERFECT=False
GENERATOR=Kruskal GENERATOR=DFS
SOLVER=AStar SOLVER=DFS
+7
View File
@@ -166,6 +166,13 @@ class DepthFirstSearchSolver(MazeSolver):
def solve(self, maze: Maze, height: int = None, def solve(self, maze: Maze, height: int = None,
width: int = None) -> str: width: int = None) -> str:
res = list()
for _ in range(50):
res.append(self.get_path(maze, height, width))
return min(res, key=lambda x: len(x))
def get_path(self, maze: Maze, height: int = None,
width: int = None) -> str:
path_str = "" path_str = ""
visited = np.zeros((height, width), dtype=bool) visited = np.zeros((height, width), dtype=bool)
path = list() path = list()