Collection of different algorithms to solve a maze and a simple maze game !
There are 3 steps in this process
- Maze Generation
- Player Mode
- Maze Solution
Algorithm used to generate Maze here is Randomized depth-first search
The steps are a follows:
- Initialize Stack with the player position cell
- Get cell from top of the stack and select it as current cell
- Mark it as visited
- While Current cell has any unvisited neighbor cells
- Choose one of the unvisited neighbor
- Remove any wall of random choice
- Push it into the stack
- If all neighbors are visited pop the cell from stack
Here you can control the player by using arrow keys on the keyboard to explore and get the feel of the grid.
To solve the maze i.e. to take the player to food, we can use different algorithms and they are as follows.
Depth First Search (DFS) is an edge-based technique. It uses the Stack data structure and performs two stages, first visited vertices are pushed into the stack, and second if there are no vertices then visited vertices are popped.
Breadth First Search (BFS) is a vertex-based technique for finding the shortest path in the graph. It uses a Queue data structure that follows first in first out. In BFS, one vertex is selected at a time when it is visited and marked then its adjacent are visited and stored in the queue.
A* is an extension of Dijkstra's algorithm with some characteristics of breadth-first search (BFS).
However, the A* algorithm introduces a heuristic into a regular graph-searching algorithm, essentially planning ahead at each step so a more optimal decision is made.
Here the Heuristic function that we use is the Manhattan distance between cell and food.
- Icons: https://www.flaticon.com
- Gifs: https://ezgif.com/video-to-gif
- Definitions: https://www.geeksforgeeks.org/
- Project: Maze
- Author: Madhav Jha
- GitHub repo: https://github.com/jhamadhav/maze
- Site Link: https://jhamadhav.com/maze