A variation on pathfinding, is finding all the paths that leads nowhere. Then putting in a start and a goal into it, and calling it a maze.

That is essentially what I have done here. For visual pezas I let the system draw all the steps along the way, so you can follow the generation of the maze.

In short the algorithm picks a starting point and then registers all the places it could possibly go next. It then picks a random spot in the set of possible steps and adds that to the maze and then repeats the process.

There are a range of other ways to generate mazes, such as recursive backtracking or simply splitting the area in half, repeatedly. I went with this version for now, but I may publish a few variations or even a UI section, where you can pick your preferred algorithm.

I have also been plotting to allow the mazes to have loops, to introduce further complexity. That does require some more math and logic that I have not yet thought out entirely. Loops need to be well planned, or we will just end up with a completely open grid, or a maze where every road is a “right way”. That is no fun.

My thoughts so far is having each step have a value for the distance it is from the last cross road or fork, and use that value to determine if a loop can be formed to that step. A very interesting addition to the whole maze generation area, that I hope to find the time to explore further.