fix Astar solver

This commit is contained in:
2026-04-03 17:59:37 +02:00
parent 6189d7f321
commit 04c28a851f
3 changed files with 7 additions and 4 deletions
+3 -3
View File
@@ -1,7 +1,7 @@
WIDTH=100 WIDTH=15
HEIGHT=100 HEIGHT=15
ENTRY=1,1 ENTRY=1,1
EXIT=5,7 EXIT=15,10
OUTPUT_FILE=con OUTPUT_FILE=con
PERFECT=True PERFECT=True
GENERATOR=Kruskal GENERATOR=Kruskal
Binary file not shown.
+4 -1
View File
@@ -84,7 +84,8 @@ class AStar(MazeSolver):
start: Start coordinates using 1-based indexing. start: Start coordinates using 1-based indexing.
end: End coordinates using 1-based indexing. end: End coordinates using 1-based indexing.
""" """
super().__init__(start, end) self.start = (start[0] - 1, start[1] - 1)
self.end = (end[0] - 1, end[1] - 1)
def h(self, n: tuple[int, int]) -> int: def h(self, n: tuple[int, int]) -> int:
"""Compute the Manhattan distance heuristic to the goal. """Compute the Manhattan distance heuristic to the goal.
@@ -196,6 +197,8 @@ class AStar(MazeSolver):
to_check, to_check,
) )
) )
if path == self.end:
break
raise Exception("Path not found") raise Exception("Path not found")
def get_rev_dir(self, current: Node) -> str: def get_rev_dir(self, current: Node) -> str: