larvaworld.lib.model.envs.maze ============================== .. py:module:: larvaworld.lib.model.envs.maze Classes ------- .. autoapisummary:: larvaworld.lib.model.envs.maze.Cell larvaworld.lib.model.envs.maze.Maze Module Contents --------------- .. py:class:: Cell(x: int, y: int) Single cell in maze grid. Represents a grid point that may be surrounded by walls in cardinal directions (North, East, South, West). Walls can be knocked down to create maze passages. Attributes: x: Cell x-coordinate in grid y: Cell y-coordinate in grid walls: Dict of wall states {"N": bool, "S": bool, "E": bool, "W": bool} wall_pairs: Class-level mapping of opposing wall directions Example: >>> cell = Cell(x=5, y=3) >>> cell.knock_down_wall(neighbor_cell, "N") >>> has_walls = cell.has_all_walls() # False .. py:attribute:: wall_pairs .. py:attribute:: walls .. py:method:: has_all_walls() -> bool Does this cell still have all its walls? .. py:method:: knock_down_wall(other: Cell, wall: str) -> None Knock down the wall between cells self and other. .. py:class:: Maze(nx: int, ny: int, ix: int = 0, iy: int = 0, height: float = 1.0) Maze generator and representation as grid of cells. Creates procedurally generated mazes using depth-first search algorithm. Produces maze as grid of Cell objects with wall connectivity, and can export to SVG or shapely LineString format for simulation obstacles. Attributes: nx: Number of cells in x-direction ny: Number of cells in y-direction ix: Starting cell x-coordinate for generation (default: 0) iy: Starting cell y-coordinate for generation (default: 0) height: Physical height of maze in simulation units (default: 1.0) maze_map: 2D array of Cell objects forming the maze Example: >>> maze = Maze(nx=10, ny=10, height=0.5) >>> maze.make_maze() # Generate maze structure >>> lines = maze.maze_lines() # Get wall LineStrings >>> maze.write_svg("output.svg") # Export to SVG .. py:attribute:: height :value: 1.0 .. py:attribute:: maze_map .. py:method:: cell_at(x: int, y: int) -> Cell Return the Cell object_class at (x,y). .. py:method:: write_svg(filename: str) -> None Write an SVG image of the maze to filename. .. py:method:: find_valid_neighbours(cell: Cell) -> List[tuple[str, Cell]] Return a list of unvisited neighbours to cell. .. py:method:: make_maze() -> None .. py:method:: maze_lines() -> list[shapely.geometry.LineString]