3 Commits

Author SHA1 Message Date
Maoake Teriierooiterai ef030f70a7 finish to synchronize the maze generator and the solver 2026-03-26 14:19:43 +01:00
Maoake Teriierooiterai 170de8813a update the gitignore 2026-03-26 13:11:36 +01:00
Maoake TERIIEROOITERAI 5aec319f7b need to fix the unperfect maze and add the function in the kruskal generator 2026-03-26 00:58:07 +01:00
8 changed files with 49 additions and 49 deletions
+1
View File
@@ -214,4 +214,5 @@ __marimo__/
# Streamlit # Streamlit
.streamlit/secrets.toml .streamlit/secrets.toml
test.txt
+3
View File
@@ -4,6 +4,9 @@ install:
run: install run: install
uv run python3 a_maze_ing.py config.txt uv run python3 a_maze_ing.py config.txt
run_windows:
.venv\Scripts\python -m a_maze_ing config.txt
debug: debug:
uv pdb python3 a_maze_ing.py config.txt uv pdb python3 a_maze_ing.py config.txt
+6 -6
View File
@@ -1,8 +1,8 @@
WIDTH=30 WIDTH=11
HEIGHT=30 HEIGHT=11
ENTRY=1,1 ENTRY=4,3
EXIT=29,29 EXIT=2,1
OUTPUT_FILE=maze.txt OUTPUT_FILE=maze.txt
PERFECT=True PERFECT=False
GENERATOR=Kruskal GENERATOR=DFS
SOLVER=AStar SOLVER=AStar
+2 -2
View File
@@ -8,8 +8,8 @@ from src.amaz_lib import Maze, MazeGenerator, MazeSolver
class AMazeIng(BaseModel): class AMazeIng(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True) model_config = ConfigDict(arbitrary_types_allowed=True)
width: int = Field(ge=3) width: int = Field(ge=4)
height: int = Field(ge=3) height: int = Field(ge=4)
entry: tuple[int, int] entry: tuple[int, int]
exit: tuple[int, int] exit: tuple[int, int]
output_file: str = Field(min_length=3) output_file: str = Field(min_length=3)
+15 -5
View File
@@ -9,7 +9,7 @@ class MazeGenerator(ABC):
def __init__(self, start: tuple, end: tuple, perfect: bool) -> None: def __init__(self, start: tuple, end: tuple, perfect: bool) -> None:
self.start = (start[0] - 1, start[1] - 1) self.start = (start[0] - 1, start[1] - 1)
self.end = (end[0] - 1, end[1] - 1) self.end = (end[0] - 1, end[1] - 1)
self.bool = bool self.perfect = perfect
@abstractmethod @abstractmethod
def generator( def generator(
@@ -58,7 +58,7 @@ class MazeGenerator(ABC):
"W": "E", "W": "E",
"E": "W" "E": "W"
} }
min_break = 3 min_break = 2
while True: while True:
count = 0 count = 0
for y in range(height): for y in range(height):
@@ -93,6 +93,7 @@ class MazeGenerator(ABC):
class Kruskal(MazeGenerator): class Kruskal(MazeGenerator):
class Set: class Set:
def __init__(self, cells: list[int]) -> None: def __init__(self, cells: list[int]) -> None:
self.cells: list[int] = cells self.cells: list[int] = cells
@@ -174,6 +175,8 @@ class Kruskal(MazeGenerator):
cells_ft = None cells_ft = None
if height > 10 and width > 10: if height > 10 and width > 10:
cells_ft = self.get_cell_ft(width, height) cells_ft = self.get_cell_ft(width, height)
if cells_ft and (self.start in cells_ft or self.end in cells_ft):
cells_ft = None
if seed is not None: if seed is not None:
np.random.seed(seed) np.random.seed(seed)
@@ -204,13 +207,20 @@ class Kruskal(MazeGenerator):
): ):
break break
print(f"nb sets: {len(sets.sets)}") print(f"nb sets: {len(sets.sets)}")
return self.walls_to_maze(walls, height, width) maze = self.walls_to_maze(walls, height, width)
if self.perfect is False:
gen = Kruskal.unperfect_maze(width, height, maze,
cells_ft)
for res in gen:
maze = res
yield maze
return maze
class DepthFirstSearch(MazeGenerator): class DepthFirstSearch(MazeGenerator):
def __init__(self, start: bool, end: bool, perfect: bool) -> None: def __init__(self, start: bool, end: bool, perfect: bool) -> None:
self.start = start self.start = (start[0] - 1, start[1] - 1)
self.end = end self.end = (end[0] - 1, end[1] - 1)
self.perfect = perfect self.perfect = perfect
self.forty_two: set | None = None self.forty_two: set | None = None
+2
View File
@@ -190,6 +190,8 @@ class DepthFirstSearchSolver(MazeSolver):
coord = self.next_cell(coord, next) coord = self.next_cell(coord, next)
for m in move: for m in move:
path_str += m path_str += m
if not path:
raise Exception("Path not found")
return path_str return path_str
@staticmethod @staticmethod
+6 -3
View File
@@ -54,12 +54,14 @@ class DataMaze:
res.update({key: DataMaze.convert_bool(data[key])}) res.update({key: DataMaze.convert_bool(data[key])})
res.update({"OUTPUT_FILE": data["OUTPUT_FILE"]}) res.update({"OUTPUT_FILE": data["OUTPUT_FILE"]})
res.update( res.update(
DataMaze.get_solver_generator(data, res["ENTRY"], res["EXIT"]) DataMaze.get_solver_generator(data, res["ENTRY"], res["EXIT"],
res["PERFECT"])
) )
return res return res
@staticmethod @staticmethod
def get_solver_generator(data: dict, entry: int, exit: int) -> dict: def get_solver_generator(data: dict, entry: tuple, exit: tuple,
perfect: bool) -> dict:
available_generator = { available_generator = {
"Kruskal": Kruskal, "Kruskal": Kruskal,
"DFS": DepthFirstSearch, "DFS": DepthFirstSearch,
@@ -68,7 +70,8 @@ class DataMaze:
"AStar": AStar, "AStar": AStar,
} }
res = {} res = {}
res["GENERATOR"] = available_generator[data["GENERATOR"]]() res["GENERATOR"] = available_generator[data["GENERATOR"]](entry, exit,
perfect)
res["SOLVER"] = available_solver[data["SOLVER"]](entry, exit) res["SOLVER"] = available_solver[data["SOLVER"]](entry, exit)
return res return res
+14 -33
View File
@@ -1,34 +1,15 @@
957D3955553B957917B93D3D15553B BD1553D3913
AB97AABBD16847D6ABAAAD452B97C6 C3AD54386AA
8687A8443EBC55538286E953A807D3 BAC5396C7AA
878506952BAD3B942EAD503E86ED52 82956C5396E
852D4383C6C384438147D2C3879796 A86D553AC53
ED2B96EC7D384792EC5792BEC38103 C295552C512
BBC2C795516C13EC51556C053AAEAA 9283B9693AA
8452BD43D4396AD552D3BBEBE803EE AAAAC456AAA
853A8552B902BABD5290029696AA93 AC2C553D2C2
C7AC2B9686EE82ABB82EEC07C7E86A 83C3D3C3E96
D3AD0683C7D3EAC2C6C3D5693956D2 C454547C547
9687E92EBBD0103857D43916A85796
C52BD2A942D2EAE857D542E946D147
D3EC12EE9692F852FFFBBE96957EBB
B87BAA97852AFED057FC07C507D506
C2942C47C7EEFFFAFFFD4517ED53C3
946BABB91553BBFEFD51796955147A
C3BA82AAC53C6AFBFFF816BEBD053A
D06AE828792B90543D568547856D42
92BC56AAD2C6A87B83916D516BD53A
AAAD13C47AD3AED46EEA95103853C2
EAAD2815143C43D3BBD0696EAED416
B847EEC3EBC57AD4407C7C3B85792B
AEBBD5503A9156BD16D1792A8796AA
87AC3BD2C42C57C383D2BEAC47C3EA
C50542B857879112E812C1297BD6BA
D3C3D44417C7EEAC3EAC52C47C516A
BA903B91693B97AB87A938157D5052
802A82EC5684414287AAEE87953AD2
EEEEEC57D547D6D6C546D54547C47E
1,1 4,3
29,29 2,1
SSSSEESSESSSENEEESWSSWSSWSSSSESESSENNNNESEESWSSSWWWSESSSSESWSEENESEEEENNNESESSSEENNNNESEESESSEENEESENNEESW EENWWNNEEESESWSEESSEEESSSSWSWWNWNWWWNNWSSSESWWNWNNNENNNNNW