Maze Drawing Applet

Go to: Applet Instructions Algorithm Example Output

The Applet

Instructions

This applet draws random mazes. Use the scrollbar to change the number of cells used to generate the maze.

The number of cells can be adjusted in the html by changing the 'mazewidth' value in the <param> tag.

Algorithm

The algorithm starts by dividing the area into an array of rectangular cells, each with 4 walls. Each cell is given a region identifier. Then, at random, we find two cells in different regions, remove the intervening wall and combine the two regions into 1. We repeat this (width x height - 1) times. Now there is only one region which contains all the cells. This guarantees that there is a route from any cell to any other cell. Also, because we've removed the smallest number of walls to achieve this state there will only be one direct route (ie. one that doesn't involve retracing your steps).