A python implementation of different maze generating and maze solving algorithms, programmed as a learning excercise. Inspired by @CodingTrain and @shiffman.
A maze object is declared as:
import maze
m = maze.Maze((width, height))
The Maze object contains the following variables:
- cells
- width
- height
- cellsize
- wallsize
- cellcolor
- wallcolor
- currentcolor
The cells array can be accessed and contains width lists with height cell elements.
The cells are arranged in the array in the [x][y] format
cellsize : Defines the size of each cell in pixels, the default is 25
wallsize : Defines the width of each wall in pixels, the default is 10
cellcolor : Defines the color of each cell in grayscale, the default is 255
wallcolor : Defines the color of each wall in grayscale, the default is 0
currentcolor : Defines the color of the highlighted current cell in grayscale, the default is 180
The Maze object contains the following functions:
- removeWalls(cellA, cellB)
- draw(current=None)
- _printCells()
- _makeCells()
Takes as an input two cells and removes the walls between them. Raises an exception if the cells are the same or if they aren't adjecent to eachother.
Returns a black and white image of the maze (numpy array of uint8), it optionally highlights the current cell.
Prints cell position data for debugging purposses, shouldn't be used.
Initializes the cells array inside the Maze, should only be used by the Maze object itself upon initialization, very costly function.
Usage:
recursive_bactracker(maze, colormap=cv2.COLORMAP_HOT, speed=33)
By default it takes a colormap to highlight the unvisited cells and the current cell, if set to None it will be rendered in grayscale.
By default it sets the animation speed to 30 FPS (waits 33 ms between frames).
- if
speedis set to 0, the code will wait for a keypress between each frame. - if
speedis set toNone, the frames won't render.