A Python application that generates and solves mazes using a recursive depth-first search (DFS) algorithm. The application includes a graphical interface that visualizes both the maze generation and solving process in real-time.
- Random maze generation using recursive backtracking
- Interactive GUI built with Tkinter
- Real-time visualization of maze generation and solving process
- Customizable maze dimensions and cell sizes
- Automated maze solving using depth-first search
- Comprehensive test suite
- Clone the repository:
git clone https://github.com/milanmarton/maze-solver.git
cd maze-solver
- Install the required dependencies:
pip install -r requirements.txt
Run the main application:
python main.py
The application will open a window displaying:
- The maze generation process in real-time
- The solving algorithm's path-finding visualization
- The final solution path highlighted in red
You can customize the maze parameters by modifying the arguments in main.py
:
maze = Maze(
x1=20, # Starting X coordinate
y1=20, # Starting Y coordinate
num_rows=14, # Number of rows in the maze
num_cols=19, # Number of columns in the maze
cell_size_x=40, # Cell width in pixels
cell_size_y=40, # Cell height in pixels
win=window # Window instance
)
You can also customize the animation speed by modifying two constants in maze.py
:
ANIMATION_SPEED = 0.15 # solving speed
CREATION_ANIMATION_SPEED = 0.001 # maze generation
The project includes a comprehensive test suite to verify the maze generation and solving functionality:
python -m unittest discover tests
maze_solver/
├── maze_solver/
│ ├── __init__.py
│ ├── gui.py # GUI components and window management
│ └── maze.py # Maze generation and solving algorithms
├── tests/
│ ├── __init__.py
│ └── test_maze.py
├── main.py
├── requirements.txt
├── LICENSE
└── README.md
-
Maze Generation: Uses a recursive depth-first search algorithm with backtracking to generate the maze:
- Starts from the top-left cell
- Randomly chooses unvisited neighboring cells
- Breaks walls between cells to create paths
- Backtracks when reaching dead ends
-
Maze Solving: Implements a depth-first search to find a path from start to finish:
- Explores possible paths from the entrance
- Marks the current path in red
- Backtracks and marks failed paths in gray
- Highlights the successful path from entrance to exit
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.