A pygame program that generates a maze and solves itself using a DFS algorithm

Maze Generator And Solver

Program Purpose: Generates a maze that then solves itself

Language: Python and Pygame

Algorithm: Randomized DFS / Floodfill / Recursive Backtracking


How the program works

Generation
  1. Maintain a matrix that keeps track of visited cells
  2. Maintain a stack that keeps track of cells on the current path
  3. Start at the top left cell
  4. Randomly choose one of the available neighbor cells
  5. If there are none, go to previous cell in the stack
  6. Color visited cells blue, current cell blue, and remove the white wall
  7. Will eventually return to the top left cell and guarantees a maze
Solving

 

 

 

To finish reading, please visit source site