![maze generator algorithm maze generator algorithm](https://www.algosome.com/articles/images/maze-generation-oval.png)
It increments the total number of cells visited in a while loop and completes when the VisitedCells equals the n x n number of grid cells. The code for implementing the Depth First Search is shown below. Each cell contains an array of 4 walls which can be "knocked down" by setting an element in the array to zero. It also allows you to print and print preview the grid:įigure 2 - Maze Generation Application Reverse engineered using the WithClass 2000 UML ToolĪs you can see from the UML design, the Maze class generates the maze and contains a collections of Cells to work the algorithm. The Application allows you to generate a maze of any grid dimension and grid cell size. Below is the design for the Maze Generator Application. Having examined the algorithm, I was able to come up with a set of classes that would help me implement it. Note: A good place to visit to understand this algorithm is the MazeWorks site.
![maze generator algorithm maze generator algorithm](https://www.baeldung.com/wp-content/uploads/sites/4/2020/11/Screenshot-2020-11-01-at-20.08.23-1024x560-1.png)
#MAZE GENERATOR ALGORITHM HOW TO#
Today's article focuses on how to generate a maze using the depth first search algorithm. Figure 1 - A sample generated maze using a 50 x 50 gridĭid you ever get the feeling that cubicles were laid out with the idea that there could be no escape? (Must be I am a bit overworked these days).