mirror of
https://github.com/maoakeEnterprise/amazing.git
synced 2026-04-28 16:04:35 +02:00
finish to synchronize the maze generator and the solver
This commit is contained in:
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
WIDTH=20
|
WIDTH=11
|
||||||
HEIGHT=20
|
HEIGHT=11
|
||||||
ENTRY=1,1
|
ENTRY=4,3
|
||||||
EXIT=2,1
|
EXIT=2,1
|
||||||
OUTPUT_FILE=maze.txt
|
OUTPUT_FILE=maze.txt
|
||||||
PERFECT=False
|
PERFECT=False
|
||||||
|
|||||||
@@ -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(
|
||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,24 +1,15 @@
|
|||||||
BD155539513D1395393B
|
BD1553D3913
|
||||||
A96D13AA96C3AC2BAAC6
|
C3AD54386AA
|
||||||
C69146A84396C52C4693
|
BAC5396C7AA
|
||||||
9380556C7AC5538553AA
|
82956C5396E
|
||||||
AC2C11555693BAA93C6A
|
A86D553AC53
|
||||||
8543C29515686AAAE912
|
C295552C512
|
||||||
AD3856C3C39696C41686
|
9283B9693AA
|
||||||
C3A853969687C5396BC3
|
AAAAC456AAA
|
||||||
BC2C3AAF83EFFFA83C52
|
AC2C553D2C2
|
||||||
A9696AAFEC157FA8293A
|
83C3D3C3E96
|
||||||
84383C6FFFAFFF86AAAA
|
C454547C547
|
||||||
A96AC13D3FAFD543AAC2
|
|
||||||
86D438452FAFFF96AA96
|
|
||||||
C553A83B87C553A92AC3
|
|
||||||
917A86A8411516A8447A
|
|
||||||
AC5683AC7801696C3B96
|
|
||||||
C393840116C414394683
|
|
||||||
BC44696AE93D296E93AA
|
|
||||||
A95396BC3AC3EA956802
|
|
||||||
C4544547C454546D5446
|
|
||||||
|
|
||||||
1,1
|
4,3
|
||||||
2,1
|
2,1
|
||||||
S
|
EENWWNNEEESESWSEESSEEESSSSWSWWNWNWWWNNWSSSESWWNWNNNENNNNNW
|
||||||
|
|||||||
Reference in New Issue
Block a user