his book shows how to build a random labyrinth. This labyrinth is very simple and consists
of walls and corridors only. But building the labyrinth base (walls and corridors) is the
most important job. After that it is easy to add more stuff like door, secrets, treasures,
monsters, etc.
Random labyrinth
T
his labyrinth generating algorithm is first filling the entire zone with walls and then
building corridors out of them. Each corridor has a random length and a random direction.
While building one corridor the algorithm is randomly spawning branches for new corridors.
The algorith will terminate if it has spawned no more branches. This can happen due to
too many bad die rolls or if there is no more space left on the zone to build any further
corridors.
'Author : Daniel, Master Sourcerer at Kitana's Cas...
'Last change: May 25, 1999
'Email : sourcerer@kitana.org
'Labyrinth array
DIM Z%(127,127)
'Stack for branches
DIM S%(2,99)
'Initialize random number generator
RANDOMIZE TIMER
'Zone elements
G%=&H0720 'corridor (black space character)
M%=&H07DB 'wall (light grey inversed space character)
Z%=&H0458 'exit (red X character)
'Size of labyrinth (must be no larger than dimensions ...
XGR%=80:YGR%=25
'Initialize labyrinth with walls
FOR J%=0 TO YGR%-1
FOR I%=0 TO XGR%-1
Z%(I%,J%)=M%
NEXT I%
NEXT J%
'Start building labyrinth from its middle
X%=XGR%/2:Y%=YGR%/2:R%=RDM%(4)-1