User:Dllu/Maze

Here is some C code for generating mazes! This code is capable of both using Prim's algorithm and depth-first search. The maze generator "grows" the maze until the counter for the number of "in" cells reaches the maximum possible. Note that my implementation of random cell selection in Prim's algorithm is extremely slow since it calls rand something on the order of O(n3) times. I was too lazy to do that using more efficient means since this started out as a program that only uses backtracking. Backtracking is very fast, however.

This maze generator is somewhat unique in that it has a one layer "padding" of cells that are already marked as being in the maze even though they're not part of the maze. The reason for this is that when growing the maze, I don't have to separately check if we have reached the boundary.

If you have any comments or suggestions for improvement, please post it in the Discussion page!

Scroll down for videos

Demonstration of capability
I also generated this extreme 2000x2000 maze which is so large (and has to be viewed at full size) that it makes no sense to view it as a thumbnail. The solution for that is here.



Other mazes
These mazes below were not generated by the above algorithm. Instead, they were made by a variant of Prim's algorithm with many starting points simultaneously. The multiple regions thus created are then linked together at different places. I made that older algorithm when I was 16 for my friend's computer science project. Unfortunately that friend didn't follow my instructions on submitting the project and got marks taken off for not compiling. Also, the code for that project is excessively verbose because the project requirements included a minimum number of lines of code. It is also very, very slow because of the same reason as I mentioned earlier about choosing cells in Prim's algorithm. So I'm too embarrassed to upload the source code for those.