fix something on the solver

This commit is contained in:
Maoake Teriierooiterai
2026-03-27 18:05:05 +01:00
parent 3c072de0f4
commit b078241359
5 changed files with 24 additions and 28 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
WIDTH=20 WIDTH=15
HEIGHT=20 HEIGHT=15
ENTRY=1,1 ENTRY=1,1
EXIT=2,2 EXIT=2,2
OUTPUT_FILE=maze.txt OUTPUT_FILE=maze.txt
+1 -1
View File
@@ -33,7 +33,7 @@ class AMazeIng(BaseModel):
return return
def solve_path(self) -> str: def solve_path(self) -> str:
return self.solver.solve(self.maze) return self.solver.solve(self.maze, self.height, self.width)
def __str__(self) -> str: def __str__(self) -> str:
res = self.maze.__str__() res = self.maze.__str__()
+3 -3
View File
@@ -152,7 +152,8 @@ class AStar(MazeSolver):
str(list(c[1].keys())[0]) for c in path if len(c[1]) > 0 str(list(c[1].keys())[0]) for c in path if len(c[1]) > 0
) )
def solve(self, maze: Maze) -> str: def solve(self, maze: Maze, height: int = None,
width: int = None) -> str:
res = self.get_path(maze.get_maze()) res = self.get_path(maze.get_maze())
if res is None: if res is None:
raise Exception("Path not found") raise Exception("Path not found")
@@ -161,8 +162,7 @@ class AStar(MazeSolver):
class DepthFirstSearchSolver(MazeSolver): class DepthFirstSearchSolver(MazeSolver):
def __init__(self, start, end): def __init__(self, start, end):
self.start = (start[1] - 1, start[0] - 1) super().__init__(start, end)
self.end = (end[1] - 1, end[0] - 1)
def solve(self, maze: Maze, height: int = None, def solve(self, maze: Maze, height: int = None,
width: int = None) -> str: width: int = None) -> str:
+2 -1
View File
@@ -1,5 +1,5 @@
from src.amaz_lib.MazeGenerator import DepthFirstSearch, Kruskal from src.amaz_lib.MazeGenerator import DepthFirstSearch, Kruskal
from src.amaz_lib.MazeSolver import AStar from src.amaz_lib.MazeSolver import AStar, DepthFirstSearchSolver
class DataMaze: class DataMaze:
@@ -68,6 +68,7 @@ class DataMaze:
} }
available_solver = { available_solver = {
"AStar": AStar, "AStar": AStar,
"DFS": DepthFirstSearchSolver
} }
res = {} res = {}
res["GENERATOR"] = available_generator[data["GENERATOR"]](entry, exit, res["GENERATOR"] = available_generator[data["GENERATOR"]](entry, exit,
+16 -21
View File
@@ -1,24 +1,19 @@
B9153957955513953953 D553955513B913B
AEA96A9569792C6BAAD6 9796C553AA86AC2
C5443AA9169281102C53 83C151146AC7C12
95556A82816C2AC2A952 C03856817C393EA
A93916A86A956C3A86D6 96EC53A8556AC3A
AEC6C542944513806953 8553FC6AFFFABC2
C395553AC393C2AC787A 8792FD5057FAC16
BC69512C7AAC56855692 E946FFFAFFF83AB
A952BAAF96AFFFAD53AE 92913BFAFD52AC2
A810686FC5057FC516C3 AEAAC6FAFFFEC3A
AAC4543FFFAFFFB96952 A904553A9555382
AC5553817FAFD52ABC3A 828557AAAD5546E
815552843FEFFF80296A 844553C6C151553
AC553A85413D55406C12 C5395439545453A
C53BAAC392C3953C13AA D546D546D555546
9386AC386A9683C56AAA
846903AE96C568517C2A
AD3A82C385397C3C5546
C12AA87AA94293AD5513
D46C6C5446D46C45556E
1,1 1,1
2,2 2,2
SSEEENENWWWS EEESWSEEEEEENNESSSESWWWSSSSSSSSWNNWWWNNWSSSSEEESWWSWNWWNENWNNNENEENNWWWNENNWNE