Algorithm

The maze randomly generates a path through a matrix of four sided cells. Each cell has four boolean variables, numbered so that 0 represents north, 1 east, 2 south, and 3 west. For each cell, a random number chooses one wall to knock down, then moves to the corresponding adjacent cell.

The algorithm iterates recusively through the matrix, starting at (0, 0) and continuing until each cell has been visited once. The following pseudocode outlines the maze generation: