12 Commits

Author SHA1 Message Date
da7e 21e9aba95f docstring to output file function 2026-04-03 18:34:18 +02:00
da7e 9fa121cdce add export file 2026-04-03 18:30:52 +02:00
da7e 04c28a851f fix Astar solver 2026-04-03 17:59:37 +02:00
da7e 6189d7f321 lint fix 2026-04-03 16:48:51 +02:00
da7e e63c2679a6 Remove test prints 2026-04-03 16:44:49 +02:00
da7e f04381568d wheel file + config 2026-04-03 16:12:36 +02:00
da7e ee4f48a5c0 add limit for height and width 2026-04-03 15:42:20 +02:00
da7e 2532a35e30 add mazegen wheel package 2026-04-03 15:10:17 +02:00
da7e 6f503bdd36 add file format checker for parsing 2026-04-03 15:00:08 +02:00
da7e 5022cfe020 add message when ft logo not display 2026-04-03 14:47:34 +02:00
Maoake Teriierooiterai 11947db62f fix the print on 42 in the maze 2026-04-03 14:20:01 +02:00
da7e 0045def73b SEED implementation 2026-04-03 13:58:41 +02:00
9 changed files with 66 additions and 41 deletions
-2
View File
@@ -215,5 +215,3 @@ __marimo__/
# Streamlit
.streamlit/secrets.toml
test.txt
mazegen-1.0.0-py3-none-any.whl
+2 -2
View File
@@ -21,7 +21,7 @@ clean:
fclean: clean
rm mazegen-1.0.0-py3-none-any.whl
lint:
lint: install
uv run flake8 . --exclude=.venv
uv run env PYTHONPATH=src python3 -m mypy --warn-return-any --warn-unused-ignores --ignore-missing-imports --disallow-untyped-defs --check-untyped-defs -p mazegen
uv run env PYTHONPATH=src python3 -m mypy --warn-return-any --warn-unused-ignores --ignore-missing-imports --disallow-untyped-defs --check-untyped-defs -p parsing
@@ -29,7 +29,7 @@ lint:
uv run env PYTHONPATH=src python3 -m mypy --warn-return-any --warn-unused-ignores --ignore-missing-imports --disallow-untyped-defs --check-untyped-defs tests
uv run env PYTHONPATH=src python3 -m mypy --warn-return-any --warn-unused-ignores --ignore-missing-imports --disallow-untyped-defs --check-untyped-defs a_maze_ing.py
lint-strict:
lint-strict: install
uv run flake8 . --exclude=.venv
uv run env PYTHONPATH=src python3 -m mypy --strict -p mazegen
uv run env PYTHONPATH=src python3 -m mypy --strict src/AMazeIng.py
+2 -4
View File
@@ -224,7 +224,6 @@ class MazeMLX:
progressively.
"""
path = amazing.solve_path()
print(path)
actual = amazing.entry
actual = (actual[0] - 1, actual[1] - 1)
maze = amazing.maze.get_maze()
@@ -483,12 +482,11 @@ def main() -> None:
"""Run the maze application."""
mlx = None
try:
mlx = MazeMLX(1000, 1000)
mlx = MazeMLX(1600, 2000)
config = Parsing.get_data_maze("config.txt")
amazing = AMazeIng(**config)
mlx.start(amazing)
with open("test.txt", "w") as output:
output.write(amazing.__str__())
amazing.export_maze()
except Exception as err:
print(err)
finally:
+6 -15
View File
@@ -1,17 +1,8 @@
WIDTH=10
HEIGHT=10
WIDTH=4
HEIGHT=4
ENTRY=1,1
EXIT=10,10
OUTPUT_FILE=con
PERFECT=True
GENERATOR=DFS
EXIT=1,2
OUTPUT_FILE=con.txt
PERFECT=False
GENERATOR=Kruskal
SOLVER=AStar
salut
#
#
#
#
#
#
#
##
Binary file not shown.
+13 -3
View File
@@ -12,8 +12,8 @@ class AMazeIng(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
width: int = Field(ge=4)
height: int = Field(ge=4)
width: int = Field(ge=4, le=100)
height: int = Field(ge=4, le=100)
entry: tuple[int, int]
exit: tuple[int, int]
output_file: str = Field(min_length=3)
@@ -21,6 +21,7 @@ class AMazeIng(BaseModel):
maze: Maze = Field(default=Maze(None))
generator: MazeGenerator
solver: MazeSolver
seed: int | None = Field(default=None)
@model_validator(mode="after")
def check_entry_exit(self) -> Self:
@@ -38,6 +39,8 @@ class AMazeIng(BaseModel):
raise ValueError("Exit coordinates exceed the maze size")
if self.entry == self.exit:
raise ValueError("Entry and Exit coordinates cant be the same")
if self.width <= 10 or self.height <= 10:
print("Height or width to low for disply forty two logo")
return self
def generate(self) -> Generator[Maze, None, None]:
@@ -48,7 +51,9 @@ class AMazeIng(BaseModel):
Yields:
The current maze state after each generation step.
"""
for array in self.generator.generator(self.height, self.width):
for array in self.generator.generator(
self.height, self.width, self.seed
):
self.maze.set_maze(array)
yield self.maze
return
@@ -61,6 +66,11 @@ class AMazeIng(BaseModel):
"""
return self.solver.solve(self.maze, self.height, self.width)
def export_maze(self) -> None:
"""Export maze, entry, exit and resolved path in output_file"""
with open(self.output_file, "w") as file:
file.write(self.__str__())
def __str__(self) -> str:
"""Return a string representation of the maze and its solution.
+14 -6
View File
@@ -20,8 +20,8 @@ class MazeGenerator(ABC):
end: Ending cell coordinates, using 1-based indexing.
perfect: Whether to generate a perfect maze with no loops.
"""
self.start = (start[0] - 1, start[1] - 1)
self.end = (end[0] - 1, end[1] - 1)
self.start = (start[1] - 1, start[0] - 1)
self.end = (end[1] - 1, end[0] - 1)
self.perfect = perfect
@abstractmethod
@@ -295,6 +295,10 @@ class Kruskal(MazeGenerator):
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):
print(
"Forty two will not be display. "
"Entry or exit set in the ft logo"
)
cells_ft = None
if seed is not None:
@@ -324,7 +328,6 @@ class Kruskal(MazeGenerator):
len(sets.sets) == 19 and cells_ft is not None
):
break
print(f"nb sets: {len(sets.sets)}")
maze = self.walls_to_maze(walls, height, width)
if self.perfect is False:
gen = Kruskal.unperfect_maze(width, height, maze, cells_ft)
@@ -347,8 +350,8 @@ class DepthFirstSearch(MazeGenerator):
end: Ending cell coordinates, using 1-based indexing.
perfect: Whether to generate a perfect maze with no loops.
"""
self.start = (start[0] - 1, start[1] - 1)
self.end = (end[0] - 1, end[1] - 1)
self.start = (start[1] - 1, start[0] - 1)
self.end = (end[1] - 1, end[0] - 1)
self.perfect = perfect
self.forty_two: set[tuple[int, int]] | None = None
@@ -369,7 +372,7 @@ class DepthFirstSearch(MazeGenerator):
The final generated maze.
"""
if seed is not None:
np.random.seed(seed)
random.seed(seed)
maze = self.init_maze(width, height)
if width > 10 and height > 10:
self.forty_two = self.get_cell_ft(width, height)
@@ -380,6 +383,11 @@ class DepthFirstSearch(MazeGenerator):
and self.end not in self.forty_two
):
visited = self.lock_cell_ft(visited, self.forty_two)
else:
print(
"Forty two will not be display. "
"Entry or exit set in the ft logo"
)
path: list[tuple[int, int]] = list()
w_h = (width, height)
coord = (0, 0)
+4 -1
View File
@@ -84,7 +84,8 @@ class AStar(MazeSolver):
start: Start 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:
"""Compute the Manhattan distance heuristic to the goal.
@@ -196,6 +197,8 @@ class AStar(MazeSolver):
to_check,
)
)
if path == self.end:
break
raise Exception("Path not found")
def get_rev_dir(self, current: Node) -> str:
+25 -8
View File
@@ -62,14 +62,12 @@ class DataMaze:
"GENERATOR",
"SOLVER",
}
set_key = {key for key in data.keys()}
if len(set_key) != len(key_test):
raise KeyError("Missing some data the len do not correspond")
res_key = {key for key in set_key if key not in key_test}
if len(res_key) != 0:
raise KeyError(
"Some Key " f"do not correspond the keys: {res_key}"
)
i = 0
for key in data:
if key in key_test:
i += 1
if len(key_test) != i:
raise Exception("Some mandatory key not provide")
@staticmethod
def convert_values(data: dict[str, str]) -> dict[str, Any]:
@@ -88,6 +86,10 @@ class DataMaze:
res: dict[str, Any] = {}
for key in key_int:
res.update({key: int(data[key])})
try:
res.update({"SEED": int(data["SEED"])})
except KeyError:
pass
for key in key_tuple:
res.update({key: DataMaze.convert_tuple(data[key])})
for key in key_bool:
@@ -181,6 +183,20 @@ class DataMaze:
return True
return False
@staticmethod
def test_file_format(file: str) -> None:
with open(file) as data_str:
for line in data_str:
if len(line.split("=", 1)) != 2:
raise Exception(
"config file format not respected. excpected format : "
"KEY=VALUE"
)
if not line.split("=", 1)[1] or line.split("=", 1)[1] == "\n":
raise Exception(
f"VALUE not provide for {line.split('=')[0]} key"
)
@staticmethod
def get_data_maze(name_file: str) -> dict[str, Any]:
"""Load, validate, and convert maze configuration data from a file.
@@ -192,6 +208,7 @@ class DataMaze:
A dictionary of validated configuration values with lowercase keys.
"""
try:
DataMaze.test_file_format(name_file)
data_str = DataMaze.get_file_data(name_file)
data_dict = DataMaze.transform_data(data_str)
DataMaze.verif_key_data(data_dict)