Wednesday, February 15, 2017

Creating a Solvable Maze

You may have noticed a lot of pictures of mazes on the internet but very few examples of the algorithms computers use to generate them. Below I have some images of a maze program I recently created in C.
The 0 and spaces are the grid. Once the maze generator starts the 0s become 2s and the spaces become 1s which link the 2s.

The next step is to randomly move the paths around the grid and if the path is finished start a new path where there are still some 0s. Once every 0 is a 2 the maze is done and will look like below.
The nice part about the finished maze above is that it is solvable from any point. Note some of the links below create the walls first. I found it easier to create the paths.

This will get you started on maze algorithms:
https://en.wikipedia.org/wiki/Maze_generation_algorithm

An actual maze generator with source code:
https://www.shadertoy.com/view/XdKGWK