A comprehensive maze-solving application that implements three different pathfinding algorithms (BFS, DFS, and A*) with both command-line and web-based interfaces.
Maze-Solver/
├── app.py # Streamlit web application
├── main.py # Command-line interface application
├── bfs.py # Breadth-First Search implementation
├── dfs.py # Depth-First Search implementation
├── astar.py # A* Search algorithm implementation
├── visualize.py # Matplotlib visualization functions
├── utils.py # Utility helper functions
├── maze.py # Maze input handling functions
├── requirements.txt # Project dependencies
└── README.md # Project documentation
| File | Algorithm | Description |
|---|---|---|
bfs.py |
Breadth-First Search (BFS) | Guarantees shortest path using queue-based exploration |
dfs.py |
Depth-First Search (DFS) | Stack-based exploration, may not find shortest path |
astar.py |
A* Search | Informed search using Manhattan distance heuristic |
Interactive web application with visual maze solving capabilities.
Features:
- Dynamic maze size selection (rows/columns)
- Interactive maze input grid
- Algorithm selection dropdown
- Real-time visualization using matplotlib
- Error handling for invalid inputs
Run with:
streamlit run app.pyTerminal-based maze solver with text output.
Features:
- Step-by-step maze input
- Algorithm selection menu
- Text-based path output
- Console visualization
Run with:
python main.py- Uses
collections.dequefor queue operations - Guarantees shortest path in unweighted grids
- Returns path as list of coordinates or
Noneif no path exists
- Uses stack (LIFO) for traversal
- May find longer paths but uses less memory
- Order-dependent path results
- Uses
heapqfor priority queue - Manhattan distance heuristic
- Combines actual cost (g) + heuristic (h) for optimal pathfinding
All dependencies are listed in requirements.txt:
streamlit==1.46.0 # Web interface
matplotlib==3.10.3 # Visualization
numpy==2.2.6 # Array operations
Install with:
pip install -r requirements.txt| Module | Function | Parameters | Returns |
|---|---|---|---|
bfs.py |
bfs(maze, start, end) |
2D list, tuple, tuple | List or None |
dfs.py |
dfs(maze, start, end) |
2D list, tuple, tuple | List or None |
astar.py |
astar(maze, start, end) |
2D list, tuple, tuple | List or None |
visualize_maze(maze, path, start, end)- Creates matplotlib figure with color-coded maze
- Colors: White (path), Black (wall), Blue (solution), Green (start), Red (end)
- Compatible with Streamlit's
st.pyplot()
| Function | Purpose |
|---|---|
is_valid_position(maze, position) |
Validates cell accessibility |
print_maze(maze) |
Prints maze to console |
is_within_bounds(maze, position) |
Checks grid boundaries |
reconstruct_path(parent, start, end) |
Builds path from parent pointers |
manhattan_distance(a, b) |
Calculates heuristic for A* |
| Function | Description |
|---|---|
input_maze() |
Interactive maze grid input |
input_coordinates(prompt, max_row, max_col) |
Validated coordinate input |
get_maze_from_user() |
Complete maze and coordinate collection |
0= Open path (walkable)1= Wall (blocked)
0 0 0 1 0
1 0 1 0 0
0 0 0 0 1
0 1 1 0 0
0 0 0 0 0
- Start coordinates:
0 0(row column) - End coordinates:
4 4(row column)
The visualize_maze() function generates a color-coded grid:
- 🟩 Green - Start position
- 🟥 Red - End position
- 🔵 Blue - Solution path
- ⬜ White - Walkable cells
- ⬛ Black - Walls
All modules include validation for:
- Invalid maze dimensions
- Out-of-bounds coordinates
- Start/end points on walls
- Invalid cell values (non-0/1)
- Missing or invalid user input
- Input Phase (
maze.py): Collect maze dimensions and grid - Algorithm Selection (
main.pyorapp.py): Choose BFS/DFS/A* - Pathfinding (algorithm module): Execute search algorithm
- Visualization (
visualize.py): Display solved maze - Output: Path coordinates and visual representation
- BFS is recommended for shortest path discovery
- A* is most efficient for larger mazes with heuristic guidance
- DFS uses less memory but may produce longer paths
- All algorithms use 4-directional movement (up, down, left, right)
Feel free to extend the project with:
- Additional heuristics for A*
- Diagonal movement support
- Animated path visualization
- Maze generation algorithms
- Performance benchmarking tools