APMaze - Meshola - web based mesh content creation ;

Meshola -- web based mesh content creation

Home Log In Facebook Contact Keep Me Posted Public Meshes Source Code Articles API & Applications

Maze Generation

This application is a maze generator class in C# that I wrote some time ago. I'm using it for development of room layouts, but its a handy thing to have

It works by building 'trees' from each side of the maze. The trees don't intersect so there is always a path from the base of any tree to the base of any other tree. This ASCII sample shows the simplest possible maze, four straight trees being generated from each side. If you examine the code you'll see that the use of four trees and their placement is arbitratry, the concept would work with more or fewer trees and in different locations.

++++++++++++
+     *    +
+     *    +
+          +
+****  ****+
+          +
+     *    +
+     *    +
++++++++++++

Usage:

    // Generate a maze
    int Rows = 30;
    int Columns = 30;

    Maze oMaze = new Maze(Rows, Columns);

    for (int i=0; i < Rows; i++) {
        for (int j=0; j < Columns; j++) {
            // If the Cells field is 0 this spot is empty, otherwise there is something there
            if (oMaze.Cells[i][j] != 0) {
            }
        }
    }

    // Get as ASCII 
    StringBuilder maze = oMaze.DumpAsASCII();

    // Get data as a C# declaration
    StringBuilder decl = oMaze.DumpAsDeclaration();
  
;