larvaworld.lib.model.envs.maze
Classes
Single cell in maze grid. |
|
Maze generator and representation as grid of cells. |
Module Contents
- class larvaworld.lib.model.envs.maze.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
- wall_pairs
- walls
- has_all_walls() bool
Does this cell still have all its walls?
- class larvaworld.lib.model.envs.maze.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
- height = 1.0
- maze_map
- write_svg(filename: str) None
Write an SVG image of the maze to filename.
- find_valid_neighbours(cell: Cell) List[tuple[str, Cell]]
Return a list of unvisited neighbours to cell.
- make_maze() None
- maze_lines() list[shapely.geometry.LineString]