Skip to content

maze generator using spanning trees via depth first search.

Notifications You must be signed in to change notification settings

nhays89/MazeGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MazeGenerator

This program builds mazes using spanning trees in a 2 dimensional grid of coordinates.

Depth-First Search

This algorithm is a randomized version of the depth-first search algorithm. Frequently implemented with a stack, this approach is one of the simplest ways to generate a maze. Consider the space for a maze being a large grid of cells (like a large chess board), each cell starting with four walls. Starting from a random cell, the algorithm selects a random neighbouring cell that has not yet been visited. The algorithm removes the wall between the two cells and marks the new cell as visited, and adds it to the stack to facilitate backtracking. The algorithm continues this process, with a cell that has no unvisited neighbours being considered a dead-end. When at a dead-end it backtracks through the path until it reaches a cell with an unvisited neighbour, continuing the path generation by visiting this new, unvisited cell (creating a new junction). This process continues until every cell has been visited, causing the algorithm to backtrack all the way back to the beginning cell.

  1. Depth-first search algorithm
  2. Recursive back-tracker implemented with Java.Util.Stack
    1. 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

    Maze

    maze

About

maze generator using spanning trees via depth first search.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages