A Rust-based maze solver that demonstrates depth-first search (DFS) and breadth-first search (BFS) using custom stack and queue implementations.
The program loads mazes from .txt files, visualizes the solving process in the terminal with colored output, and shows whether each maze can be solved.
- Parse and validate maze definitions from text files.
- Solve mazes using:
- Stack (DFS) via
MyStack - Queue (BFS) via
MyQueue
- Stack (DFS) via
- Step-by-step animated visualization in the terminal:
@→ current position+→ visited squares#→ walls.→ open spaceo→ start*→ finish
- Modular design with traits (
Agenda), generics, and custom data structures.
src/
├── main.rs # Entry point: loads mazes and runs solvers
├── location.rs # Maze coordinates and neighbor calculation
├── maze.rs # Maze parsing, solving, and visualization
├── maze_data_structures.rs # Agenda trait, stack, and queue implementations
└── square.rs # Maze cell definitions (wall, open, start, finish)
mazes/ # Place your maze .txt files here- Rust (latest stable)
- A terminal that supports ANSI escape codes for colored output (e.g., most Linux/macOS terminals, or Windows Terminal)
git clone https://github.com/EyeBrawler/maze-solver.git
cd maze-solverEach maze file must:
- Start with two integers: width height
- Followed by exactly
heightrows ofwidthcharacters - Valid characters:
#→ wall.→ openo→ start*→ finish
Example (mazes/example.txt):
7 5
#######
#o...*#
#.#.#.#
#.....#
#######
cargo run- Load each .txt maze in mazes/
- Solve it once with a stack (DFS)
- Solve it again with a queue (BFS)
Loading maze from file: "mazes/example.txt"
Maze loaded successfully!
Solved with a stack: true
Solved with a queue: true
- Rust → safe systems programming
- Traits & Generics → reusable solver interface (Agenda)
- Custom Data Structures → MyStack (DFS) and MyQueue (BFS)
- HashSet → track visited locations
- ANSI terminal colors via colored
This project is for educational purposes. Feel free to fork and modify.