/maze-generator

A Perfect Random Maze generator with given width and height using the "Recursive backtracking" algorithm.

Primary LanguageC#

Perfect Maze Generator using Unity-3D and C#

This project is a simple Unity-3D project that generates a random perfect maze with given width and height data using "Recursive backtracker" algorithm each time.

Watch a short clip of this project.

How Recursive-backtracker Algorithm works?

The depth-first search algorithm of maze generation is frequently implemented using backtracking:
  1. Make the initial cell the current cell and mark it as visited.
  2. While there are unvisited cells.
    1. If the current cell has any neighbours which have not been visited
      1. Choose randomly one of the unvisited neighbours
      2. Push the current cell to the stack
      3. Remove the wall between the current cell and the chosen cell
      4. Make the chosen cell the current cell and mark it as visited
    2. Else if stack is not empty
      1. Pop a cell from the stack
      2. Make it the current cell

    Read more about maze generation algorithms.