Dungeon map generator based on The Tower of Druaga
The controller at the bottom of the demo page enables you to change the following parameters.
- Random seed
- Floor size (width and height)
As you change the parameters, a reproducible floor map will be generated.
The goal of this repository is to study the procedure for generating a floor map of The Tower of Druaga.
This code is not a strict emulation of the Tower of Druaga.
The floor map of the Tower of Druaga has been generated based on the following requirements.
- Floor, pillar, and wall map data is not in ROM.
- You can always step on all floors without using mattocks (wall-destroying item). There are no enclosed spaces.
- There are no large rooms. Every floor becomes a passage.
On the actual ROM, the program generates a floor map from 8-bit integers. The number of floor is the seed value of the pseudo-random number generator.
Only on the 60th (last) floor, the seed value is 255. If you give the same floor size and seed value, the same map will always be generated.
The reason why the Tower of Druaga doesn't allow for large rooms is because at the time, the floor space limited by the capabilities of the hardware. If floor generator didn't create a long pathway, users could traverse the floor in a very short amount of time.
The floor generation algorithm requires a Pseudo-random number generator with seed. In this case, the floor generator uses the Xorshift algorithm.
The floor map of the Tower of Druaga consists of 4 elements.
- outer walls : ■️
- tile : □
- pillars : ●
- wall : |
■ ■ ■ ■ ■ ■ ■
■ □ | □ □ □ ■
■ □ ● □ ● ─ ■
■ □ □ □ □ □ ■
■ ■ ■ ■ ■ ■ ■
Outer walls enclose the floor. Tile allows characters to come and go. Pillars stand evenly spaced, and the walls extend from here.
The Tower of Druaga's algorithm generates a floor map by following these steps.
- Pick up the pillars in order from top left to bottom right.
- Extend the wall in a random direction from a pillar where the wall has not yet been generated.
- Move to the pillar at the destination of the wall.
- Repeat step 2 and 3. Choose from three directions to extend the wall without going backwards. The floor generator make routes with walls.
- When route reach the outer wall, or the pillars where the wall already extends, it' s done.
By repeating this procedure, the walls extend from the pillars to generate the floor.
Walls always start with a pillar and end with an outer wall. So, the route does not divide the floor.
If you follow the steps to build a wall, you will have an enclosed space.
- The wall stretches and hits the route.
- The route surrounds the head of the wall.
The floor generator creates a closed space when the walls collide with each other during generation. Imagine the shape of the number 6.
● ← ●
↓
● ← ●
↓ ↑
● → ●
In the event of a collision, the floor generator cancels the last move and redraws the direction.
If there are walls on all four sides of a pillar, redrawing the direction does not solve the problem.
● ← ● ← ●
↓
● ● ← ●
↓ ↑
● → ● → ●
In this case, the generator will cancel the entire route and start over.
- Clone or download the source from GitHub.
npm install
npm run publish
- Files output to
docs
folder, the local http server will start.