Yet again, another CLI maze generator written in Python3, but with a cool visualization to video!
Help Mr.Squeaks 🐁 to get that 🧀! But beware of the sticky spider webs 🕷️🕸️, they will slow you down!
Python being the FASTEST 🚀 language known to man, you can take the coffee break YOU 🫵 deserve and get your self a nice maze with its generation and solving steps in a video when you come back.
Install the required libraries:
pip install -r requirements.txt
- numpy
- pillow
- opencv-python
To show all CLI options use the -h
option:
python maze.py -h
Just specify image name (with its format) to the -o
argument. Two images of a maze will be generated:
- without a solution
- with a solution (the shortest path)
Example:
python maze.py -o example.png
example.png (left), example.solution.png (right)
Maze solving uses the dijkstra algorithm to compute all cells weights (min path length from source).
The -g
option, will draw those weights in the form of a heatmap.
Example:
python maze.py -o example.png -g
example.png (left), example.solution.png (right)
One can add webs that slow down Mr.Squeaks by setting a penalty weight and a random spawn chance with the -w
argument. -w
waits for a string with a int
and a float
separated by a ;
:
-w "penality(int);spawn_chance([0,1])"
But by default, the generated maze is a perfect maze, which means there is only one path covering the whole maze. This makes webs unavoidable !
To prevent this, one can randomly break some walls by supplying a probability (float between 0 and 1) to the -b
option.
Example:
python maze.py -o example.png -w "4;0.1" -b 0.2
example.png (left), example.solution.png (right)
-
The solution purposely walks around the first spider web
If an image is specified, one can use the -v
option to generate a mp4 video showing the maze generation and maze solving.
Example:
python maze.py -o example.png -v
Example with ffmpeg:
ffmpeg -i example.mp4 tmp.mp4 # up to 80% reduction with negligible quality loss
rm example.mp4
mv tmp.mp4 example.mp4