This project is a Python maze generator that uses a backtracking algorithm to create fully filled mazes, and then solves the maze using depth-first search. The generated mazes can be exported as images for easy visualization.
maze.py
: Contains theMaze
class that implements the generation, solving, and image export of the maze.maze.png
: Image of the generated maze and its solution (automatically generated).
- Python 3.x
- Numpy
- Pillow
- Windows: Ensure that bash is available. This can be done through Git Bash or Windows Subsystem for Linux (WSL). To run the script, use the following command:
bash setup_env.sh
- Linux and macOS: Before running the script, ensure it has execution permissions. You can set this by running:
chmod +x setup_env.sh
- Additional Notes If you encounter any issues with the script or have questions about the setup process, feel free to ask for assistance.
-
Clone the repository https://github.com/ProWilliam/Maze_generator.git
-
Or download the maze.py file.
-
Ensure you have Python and the dependencies installed.
-
Run the script as follows:
python maze.py
The generated mazes are displayed as images, with the maze structure represented in black and the paths in white. The solution path is highlighted in red. Below are some examples of what the mazes look like:
After running the script, the maze and its solution will be saved as maze.png
in the project directory. You can open this image with any image viewer to see the maze layout and the solution path.