__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"]
-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,
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: