mirror of
https://github.com/maoakeEnterprise/amazing.git
synced 2026-04-28 16:04:35 +02:00
Compare commits
3 Commits
24748c47ad
...
solver_dfs
| Author | SHA1 | Date | |
|---|---|---|---|
| ef030f70a7 | |||
| 170de8813a | |||
| 5aec319f7b |
@@ -214,4 +214,5 @@ __marimo__/
|
||||
|
||||
# Streamlit
|
||||
.streamlit/secrets.toml
|
||||
test.txt
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ install:
|
||||
run: install
|
||||
uv run python3 a_maze_ing.py config.txt
|
||||
|
||||
run_windows:
|
||||
.venv\Scripts\python -m a_maze_ing config.txt
|
||||
|
||||
debug:
|
||||
uv pdb python3 a_maze_ing.py config.txt
|
||||
|
||||
|
||||
+6
-6
@@ -1,8 +1,8 @@
|
||||
WIDTH=30
|
||||
HEIGHT=30
|
||||
ENTRY=1,1
|
||||
EXIT=29,29
|
||||
WIDTH=11
|
||||
HEIGHT=11
|
||||
ENTRY=4,3
|
||||
EXIT=2,1
|
||||
OUTPUT_FILE=maze.txt
|
||||
PERFECT=True
|
||||
GENERATOR=Kruskal
|
||||
PERFECT=False
|
||||
GENERATOR=DFS
|
||||
SOLVER=AStar
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ from src.amaz_lib import Maze, MazeGenerator, MazeSolver
|
||||
class AMazeIng(BaseModel):
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||
|
||||
width: int = Field(ge=3)
|
||||
height: int = Field(ge=3)
|
||||
width: int = Field(ge=4)
|
||||
height: int = Field(ge=4)
|
||||
entry: tuple[int, int]
|
||||
exit: tuple[int, int]
|
||||
output_file: str = Field(min_length=3)
|
||||
|
||||
@@ -9,7 +9,7 @@ class MazeGenerator(ABC):
|
||||
def __init__(self, start: tuple, end: tuple, perfect: bool) -> None:
|
||||
self.start = (start[0] - 1, start[1] - 1)
|
||||
self.end = (end[0] - 1, end[1] - 1)
|
||||
self.bool = bool
|
||||
self.perfect = perfect
|
||||
|
||||
@abstractmethod
|
||||
def generator(
|
||||
@@ -58,7 +58,7 @@ class MazeGenerator(ABC):
|
||||
"W": "E",
|
||||
"E": "W"
|
||||
}
|
||||
min_break = 3
|
||||
min_break = 2
|
||||
while True:
|
||||
count = 0
|
||||
for y in range(height):
|
||||
@@ -93,6 +93,7 @@ class MazeGenerator(ABC):
|
||||
|
||||
|
||||
class Kruskal(MazeGenerator):
|
||||
|
||||
class Set:
|
||||
def __init__(self, cells: list[int]) -> None:
|
||||
self.cells: list[int] = cells
|
||||
@@ -174,6 +175,8 @@ class Kruskal(MazeGenerator):
|
||||
cells_ft = None
|
||||
if height > 10 and width > 10:
|
||||
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:
|
||||
np.random.seed(seed)
|
||||
@@ -204,13 +207,20 @@ class Kruskal(MazeGenerator):
|
||||
):
|
||||
break
|
||||
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):
|
||||
def __init__(self, start: bool, end: bool, perfect: bool) -> None:
|
||||
self.start = start
|
||||
self.end = end
|
||||
self.start = (start[0] - 1, start[1] - 1)
|
||||
self.end = (end[0] - 1, end[1] - 1)
|
||||
self.perfect = perfect
|
||||
self.forty_two: set | None = None
|
||||
|
||||
|
||||
@@ -190,6 +190,8 @@ class DepthFirstSearchSolver(MazeSolver):
|
||||
coord = self.next_cell(coord, next)
|
||||
for m in move:
|
||||
path_str += m
|
||||
if not path:
|
||||
raise Exception("Path not found")
|
||||
return path_str
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -54,12 +54,14 @@ class DataMaze:
|
||||
res.update({key: DataMaze.convert_bool(data[key])})
|
||||
res.update({"OUTPUT_FILE": data["OUTPUT_FILE"]})
|
||||
res.update(
|
||||
DataMaze.get_solver_generator(data, res["ENTRY"], res["EXIT"])
|
||||
DataMaze.get_solver_generator(data, res["ENTRY"], res["EXIT"],
|
||||
res["PERFECT"])
|
||||
)
|
||||
return res
|
||||
|
||||
@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 = {
|
||||
"Kruskal": Kruskal,
|
||||
"DFS": DepthFirstSearch,
|
||||
@@ -68,7 +70,8 @@ class DataMaze:
|
||||
"AStar": AStar,
|
||||
}
|
||||
res = {}
|
||||
res["GENERATOR"] = available_generator[data["GENERATOR"]]()
|
||||
res["GENERATOR"] = available_generator[data["GENERATOR"]](entry, exit,
|
||||
perfect)
|
||||
res["SOLVER"] = available_solver[data["SOLVER"]](entry, exit)
|
||||
return res
|
||||
|
||||
|
||||
@@ -1,34 +1,15 @@
|
||||
957D3955553B957917B93D3D15553B
|
||||
AB97AABBD16847D6ABAAAD452B97C6
|
||||
8687A8443EBC55538286E953A807D3
|
||||
878506952BAD3B942EAD503E86ED52
|
||||
852D4383C6C384438147D2C3879796
|
||||
ED2B96EC7D384792EC5792BEC38103
|
||||
BBC2C795516C13EC51556C053AAEAA
|
||||
8452BD43D4396AD552D3BBEBE803EE
|
||||
853A8552B902BABD5290029696AA93
|
||||
C7AC2B9686EE82ABB82EEC07C7E86A
|
||||
D3AD0683C7D3EAC2C6C3D5693956D2
|
||||
9687E92EBBD0103857D43916A85796
|
||||
C52BD2A942D2EAE857D542E946D147
|
||||
D3EC12EE9692F852FFFBBE96957EBB
|
||||
B87BAA97852AFED057FC07C507D506
|
||||
C2942C47C7EEFFFAFFFD4517ED53C3
|
||||
946BABB91553BBFEFD51796955147A
|
||||
C3BA82AAC53C6AFBFFF816BEBD053A
|
||||
D06AE828792B90543D568547856D42
|
||||
92BC56AAD2C6A87B83916D516BD53A
|
||||
AAAD13C47AD3AED46EEA95103853C2
|
||||
EAAD2815143C43D3BBD0696EAED416
|
||||
B847EEC3EBC57AD4407C7C3B85792B
|
||||
AEBBD5503A9156BD16D1792A8796AA
|
||||
87AC3BD2C42C57C383D2BEAC47C3EA
|
||||
C50542B857879112E812C1297BD6BA
|
||||
D3C3D44417C7EEAC3EAC52C47C516A
|
||||
BA903B91693B97AB87A938157D5052
|
||||
802A82EC5684414287AAEE87953AD2
|
||||
EEEEEC57D547D6D6C546D54547C47E
|
||||
BD1553D3913
|
||||
C3AD54386AA
|
||||
BAC5396C7AA
|
||||
82956C5396E
|
||||
A86D553AC53
|
||||
C295552C512
|
||||
9283B9693AA
|
||||
AAAAC456AAA
|
||||
AC2C553D2C2
|
||||
83C3D3C3E96
|
||||
C454547C547
|
||||
|
||||
1,1
|
||||
29,29
|
||||
SSSSEESSESSSENEEESWSSWSSWSSSSESESSENNNNESEESWSSSWWWSESSSSESWSEENESEEEENNNESESSSEENNNNESEESESSEENEESENNEESW
|
||||
4,3
|
||||
2,1
|
||||
EENWWNNEEESESWSEESSEEESSSSWSWWNWNWWWNNWSSSESWWNWNNNENNNNNW
|
||||
|
||||
Reference in New Issue
Block a user