Maze#
- class mazely.Utilities#
A class to perform maze-related utility functions.
- save_grid(grid, file_path, cell_size=15, line_width=2)#
Save a maze as an SVG file.
- save_solution(grid, solution_path, file_path, cell_size=15, line_width=2, colormap='RdYlGn')#
Save a maze and its solution as an SVG file.
For more colormap selection, click here.
- Parameters:
grid (ndarray) – A two-dimensional array of cells representing a rectangular maze.
solution_path (list[tuple[int, int]]) – An ordered list of cell locations representing the solution path.
file_path (str) – A path wherein the SVG file is saved.
cell_size (int) – The size of each cell in pixels.
line_width (int) – The width of the wall lines in pixels.
colormap (str) – A colormap included with Matplotlib.
- show_grid(grid)#
Display a plot of a rectangular, two-dimensional maze.
Visualization is done with Matplotlib.
- Parameters:
grid (ndarray) – A two-dimensional array of cells representing a rectangular maze.
- show_solution(grid, solution_path)#
Display a plot of a rectangular, two-dimensional maze and its solution path.
Visualization is done with Matplotlib.
- class mazely.Maze(rows=3, columns=3, path=None, seed=random.randrange(sys.maxsize), generator=RecursiveBacktracking(), solver=ShortestPath())#
A class to represent a rectangular, two-dimensional maze.
- solution_path#
An ordered list of cell locations representing the solution path.
- generator#
An instance of a
MazeGenerator
subclass used for generating mazes. Defaults toRecursiveBacktracking
.- Type:
- solver#
An instance of a
MazeSolver
subclass used for solving mazes. Defaults toShortestPath
.- Type:
- add_goal_cells(*cells)#
Add cell locations as a goal cell.
- Parameters:
- Raises:
ValueError – If either row or column is out of range.
- static are_cells_adjacent(*cells)#
Whether each cell is adjacent to the next.
- Returns:
True
if each cell is adjacent to the next.False
if otherwise. Also,False
if only one cell is provided as an argument.- Return type:
- generate(rows, columns, seed=random.randrange(sys.maxsize))#
Generate a new maze and overwrite to
grid
.
- get_random_cell()#
Get a random cell location.
- remove_wall(cell, neighbor)#
Remove the wall between a cell and its neighbor.
- set_goal_cell(row, column)#
Set a cell location as a goal cell.
- Parameters:
- Raises:
ValueError – If either row or column is out of range.
- set_start_cell(row, column)#
Set a cell location as the start cell.
- Parameters:
- Raises:
ValueError – If either row or column is out of range.
- solve()#
Solve the maze with a specific configuration.