From b6822741021803767b2b5b901f80d455d67045fd Mon Sep 17 00:00:00 2001 From: Maoake Teriierooiterai Date: Sun, 29 Mar 2026 14:31:04 +0200 Subject: [PATCH] opti path --- config.txt | 4 ++-- src/amaz_lib/MazeSolver.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/config.txt b/config.txt index f441fba..f93121d 100644 --- a/config.txt +++ b/config.txt @@ -3,6 +3,6 @@ HEIGHT=11 ENTRY=1,1 EXIT=11,11 OUTPUT_FILE=maze.txt -PERFECT=True +PERFECT=False GENERATOR=Kruskal -SOLVER=AStar +SOLVER=DFS diff --git a/src/amaz_lib/MazeSolver.py b/src/amaz_lib/MazeSolver.py index 18033e6..f66c9a3 100644 --- a/src/amaz_lib/MazeSolver.py +++ b/src/amaz_lib/MazeSolver.py @@ -166,6 +166,13 @@ class DepthFirstSearchSolver(MazeSolver): def solve(self, maze: Maze, height: int = None, width: int = None) -> str: + res = list() + for _ in range(60): + 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 = "" visited = np.zeros((height, width), dtype=bool) path = list()