]> Untitled Git - axy/ft/a-maze-ing.git/commitdiff
Simple module for the subject
authorAxy <gilliardmarthey.axel@gmail.com>
Sun, 29 Mar 2026 23:06:28 +0000 (01:06 +0200)
committerAxy <gilliardmarthey.axel@gmail.com>
Sun, 29 Mar 2026 23:06:28 +0000 (01:06 +0200)
a_maze_ing.py
mazegen/__init__.py
mazegen/maze/maze.py
mazegen/maze/pattern.py

index 14544c9c616e3264936213fc41f41f4dad2734a7..40da036edc2449a5a98dd96514fbf4b9d11fd3a2 100644 (file)
@@ -63,7 +63,7 @@ pattern = Pattern(config.maze_pattern).centered_for(maze.dims, excluded)
 
 
 def maze_main() -> None:
-    pattern.fill(maze)
+    pattern.write_to_maze(maze)
     maze.outline()
 
     walls_const = set(maze.walls_full())
index 0024978a86f0dd05d9727cfa45c834eca51ae432..3d57222c9d3748bdff017bae5ea10301016709d9 100644 (file)
@@ -1,2 +1,56 @@
 __version__ = "1.0.0"
 __author__ = "luflores & agilliar"
+
+
+class MazeGenerator:
+    """
+    A very simple but not very practical maze generator
+    The options have the same effect as in the config file
+    """
+
+    def __init__(
+        self,
+        dims: tuple[int, int],
+        entry: tuple[int, int],
+        exit: tuple[int, int],
+        perfect: bool = True,
+        seed: int | None = None,
+    ) -> None:
+        from mazegen.maze import (
+            Maze,
+            Pattern,
+            make_perfect,
+            make_pacman,
+            NetworkTracker,
+            PacmanTracker,
+        )
+        from mazegen.utils import IVec2
+        import random
+
+        prev_rand = random.getstate()
+        random.seed(seed)
+
+        maze = Maze(IVec2(*dims), IVec2(*entry), IVec2(*exit))
+        maze.outline()
+        Pattern(Pattern.FT_PATTERN).centered_for(
+            maze.dims, {maze.entry, maze.exit}
+        ).write_to_maze(maze)
+        walls_const = set(maze.walls_full())
+
+        make_perfect(maze, NetworkTracker(maze))
+        if not perfect:
+            make_pacman(maze, walls_const, PacmanTracker(maze))
+
+        random.setstate(prev_rand)
+        self.__maze = maze
+
+    def get_output(self) -> str:
+        """
+        Returns the output as formatted for the output file
+        """
+        from mazegen.maze.output import format_output
+
+        return format_output(self.__maze)
+
+
+__all__ = ["MazeGenerator"]
index 3ac95e1a88c106fdbbd9f742ee78d630bca91408..a9f0ea8fe828df3d04555643caba6ad8dd1beed3 100644 (file)
@@ -1,4 +1,4 @@
-from typing import Callable, Generator, Iterable
+from typing import Callable, Generator, Iterable, overload
 from mazegen.config.config_parser import Config
 from mazegen.utils import (
     CellCoord,
@@ -16,19 +16,30 @@ class Maze:
     Its observers are called whenever the status of a wall changes
     """
 
-    def __init__(self, config: Config) -> None:
-        self.dims = IVec2(config.width, config.height)
-        self.observers: set[MazeObserver] = set()
-        self.entry: CellCoord = (
-            CellCoord(0, 0)
-            if config.entry is None
-            else CellCoord(config.entry)
-        )
-        self.exit: CellCoord = (
-            CellCoord(self.dims - IVec2.splat(1))
-            if config.exit is None
-            else CellCoord(config.exit)
+    @overload
+    def __init__(self, config: Config) -> None: ...
+    @overload
+    def __init__(self, dims: IVec2, entry: IVec2, exit: IVec2, /) -> None: ...
+
+    def __init__(
+        self,
+        config: Config | IVec2,
+        entry: IVec2 = IVec2.splat(0),
+        exit: IVec2 = IVec2.splat(0),
+    ) -> None:
+        self.dims = (
+            IVec2(config.width, config.height)
+            if isinstance(config, Config)
+            else config
         )
+        self.observers: set[MazeObserver] = set()
+        self.entry: CellCoord = CellCoord(entry)
+        self.exit: CellCoord = CellCoord(exit)
+        if isinstance(config, Config):
+            if config.entry is not None:
+                self.entry = CellCoord(config.entry)
+            if config.exit is not None:
+                self.exit = CellCoord(config.exit)
         self.__walls_full: dict[WallCoord, None] = {}
 
     def get_wall(self, coord: WallCoord) -> bool:
index 29df958cbb9d4034ea739312738028662badf414..b26c9444cb44c1beae5429c7978ff87c2910209a 100644 (file)
@@ -140,9 +140,9 @@ class Pattern:
                     return normalized.offset(pos)
         return Pattern([])
 
-    def fill(self, maze: "Maze") -> None:
+    def write_to_maze(self, maze: "Maze") -> None:
         """
-        Fills the pattern into the maze by filling the walls of each pattern
+        Writes the pattern into the maze by filling the walls of each pattern
         cell
         """
         for cell in self.__cells: