Maze Solver: Watch AI Find the Optimal Path
Generate any maze, then watch the A* algorithm highlight the optimal solution path in real time. Learn how AI pathfinding works — step by step, completely free.
How to Use the Maze Solver
- 1
Generate a Maze
Visit the maze generator and choose your preferred size (5×5 for quick demos, 25×25 for impressive visualizations). Click Generate.
- 2
Click Solve
In Optimal Path mode, click the Solve button. The A* algorithm begins exploring the maze immediately.
- 3
Watch the Solution Appear
See the explored cells highlighted in real time, then watch the final optimal path traced from start to exit in a distinct color.
How A* Finds the Optimal Path
The A* algorithm (pronounced "A-star") is the most widely used pathfinding algorithm in games, robotics, and navigation software. It works by maintaining two lists:
- ▸Open Set — cells that need to be evaluated next. Each cell has a score: f(n) = g(n) + h(n), where g is the actual cost from start and h is the heuristic estimate to the goal.
- ▸Closed Set — cells already fully evaluated. A* never re-visits these, making it significantly faster than Dijkstra's algorithm on grid mazes.
- ▸Heuristic (h) — we use Manhattan distance (|x₁-x₂| + |y₁-y₂|), which is admissible for grid-based mazes and guarantees the optimal solution path is found.
Deep dive: Maze Generation Algorithms → | How to Solve Mazes →