![endless maze generator algorithm endless maze generator algorithm](https://m.media-amazon.com/images/I/411QJx0Q8tL._SL160_.jpg)
![endless maze generator algorithm endless maze generator algorithm](http://2.bp.blogspot.com/-BvWwWxvPG-g/VYmcJ7tUyxI/AAAAAAAAAIY/qd-1yoFl4w0/s1600/yay.png)
This will allow us to keep our main loop the same, while encapsulating the MustChangeDirection functionality within our DirectionPicker class. I am going to try and incorporate the MustChangeDirection functionality within the GetNextDirection method. If we look at our current Generate main loop we notice that we depend on the DirectionPicker to select the next direction using the GetNextDirection method. The above returns more “True” values as the changeDirectionModifier increases in value until it reaches 100 where it will always return “True”.
![endless maze generator algorithm endless maze generator algorithm](https://bedroomproducersblog.com/wp-content/uploads/2011/02/kirnu.png)
A changeDirectionModifier value of 0 will never be greater than any of the random values and will always return “False”.
#Endless maze generator algorithm code#
The code above compares the provided changeDirectionModifier to a random value between 0 and 99. Return changeDirectionModifier > (0, 99) value of 0 will never change direction changeDirectionModifier of 100 will always change direction Public bool MustChangeDirection( int changeDirectionModifier) The test for this requirement is as follows. In order to implement this requirement we will need a method to calculate if we need to change the direction. If the parameter value is 100 then we should always change our direction. We should change the direction if the previous direction is no longer valid. If the parameter value is 0 then the algorithm should use the previous direction for the next cell. The author of the algorithm recommends some kind of “randomness” parameter which will influence how often we change directions. Step 6 of the algorithm allows us to customize how often the algorithm chooses a new direction when creating corridors. If the randomness is 100, you get the algorithm given above-corridors that twist and turn unpredictably from cell to cell. If the value of randomness is 0, the corridors go straight until they run into a wall or another corridor-you wind up with a maze with lots of long, straight halls. This is a percentage value (0–100) that determines how often the direction of a corridor changes. Once that process finishes, you’ll have your maze! There are a few variations you can do to make the maze more interesting for example, my dungeon generator has a parameter called “randomness”.
#Endless maze generator algorithm series#
In part 5 of this article series we will look at implementing some additional features to make the maze a little more interesting and start the process of transitioning the maze into more of a dungeon. Next we updated our Generate function to incorporate this new functionality and also implemented the requirements for step 5 of the algorithm which basically created our maze as seen in the screen shot above. The implementation was quite easy as we just removed the walls between the two adjacent cells to form a corridor. The next piece of functionality was a new method on the Map class to create a corridor between two adjacent cells. Each side of a cell could either be a wall or empty. The cell class allowed us to implement functionality to keep track of the sides of each cell. In part 4 of the Generating Random Dungeons article series we implemented the functionality to meet the requirements of step 4 and 5 of the random dungeon generation algorithm.ĭuring this process we refactored the Map class to make use of a new Cell class. Technorati Tags: Dungeon Generation, Test-driven Development Introduction