Navigation: Home / JMaze / About JMazeJMaze is the java port of the well known XMaze which comes with the distributions of the X11 software. It is a program for generating and solving labyrinths. I ported it to java to play a little bit around with it and to understand how it works. Basically, it maintains a 2 dimensional playfield. In every tile there are 4 walls and 4 doors (could be a bit simplified - but who cares). It creates also a solution path through the maze (blue).The maze is created step by step. From the start location one step is done in a random direction. Every newly touched field (tile) is marked as occupied and the door and wall flags are set. Each step is recorded in the path list. If no movement is possible because the last field is occupied then the algorithm does on step backward and tries again with the next direction it took at this step before. This is repeated until the end location is finally reached and the path is stored as solution path. In method choose_door() is also checked if the filed above, right, below or left the Flag „DOOR_IN_ANY“ is set. If so, then this direction is choosen immediately. Otherwise every direction is checked and added to the vector of possible moves, which is then randomized. One might think that this algorithm lets the number of branch points raise at the end of the path. I could not verify that. The structure of the generated mazes look pretty smooth and random. You can download the source below, as well as the jar file. Have Fun! Links ContentJmaze.jar - Applet binary JMaze.java - Source code of the java port Maze.c - X11 program source (original) |
|
Rene Stoeckel, September 2006 |