The maze generator is simple to understand and simple to implement. Start the maze as a solid block of stone. To begin, select a random spot in the 'empty' maze. Pick a random direction from there, and bash a hole from the source to the new destination. From the spot we are now, pick another random direction. If the destination cell is still 'closed' (ie. it hasn't been bashed to or 'visited' yet), bash through the wall into the cell. Continue this way until a visited cell is found. When the cell we want to bash to has been visited before, we stay where we are, and simply pick another random direction. If there is no direction we can bash to, we pick a new source, a previously visited square, and the whole process starts anew. As our list of 'closed' squares shrinks, the process of finding a new unvisited quare to bash to can start taking up more time than we want it to. You can picture this easily by imagining a single closed cell in a field of 500*500 cells. We'd have to wait until we 'pick' an adjecent open square AND pick the right direction to reach the closed square. So, to shrink the cpu hog 'peak', we swap lists halfway through. When we've spent over half the closed squares, we turn around: we start searching for open squares, move to an adjecent closed square, and /then/ we bash to the square we just picked. When we've visited all squares, the maze's start and end are easily picked, since there is only one path between any two squares; simply pick two walls on any edge. Preferably on opposite sides of the maze. ########## ########## ########## ########## ########## ########## #X-####### ########## Pick random cell. ########## ########## ########## ########## ##|####### # ####### ########## Pick random direction. ####|##### # ##### # ######## # ####### ## ####### # ####### ########## Hit a visited or limited cell ########## # ##### # ##|##### # ####### ## ####### # ####### ########## Pick a different direction ########## # - ### # ## # ### # # ### ## ####### # ####### ########## No proper direction possible ########## # # ### # ## # ### # #X ### ## #|##### # ####### ########## Pick a new position and direction ########## # # # # # ## # # # # # # # ## # ### # # # # ########## Continue this until all squares have been visited ########## # # # # # ## # # # X # # # ## # ### # # # X ########## Pick two random cells on opposite sides ########## # # # # # ## # # # i # # # ## # ### # # # o ########## All done!