Skip to content
This repository was archived by the owner on Mar 8, 2021. It is now read-only.
This repository was archived by the owner on Mar 8, 2021. It is now read-only.

Procedural Dungeon Generation #1 #1

Open
@a327ex

Description

@a327ex

2013-06-30 23:43

This post briefly explains a technique for generating randomized dungeons that is loosely based on the one explained here:


Grid Generation

Generate a grid:


Grid Difficulty Coloring

Color the grid with x red rooms (hard), y blue rooms (medium) and z green rooms (easy) such that x+y+z = n rooms in the grid. x, y and z will be used as controls for difficulty.

  1. First color the grid with x red rooms such that no red room has another red neighbor;
  2. Then for each red room color one neighbor blue and one neighbor green;
  3. Color the rest of the rooms randomly with the remaining number of rooms for each color.


Dungeon Path Creation

Choose two nodes that are far apart enough and then find a path between them while mostly avoiding red rooms. If you choose a proper x, since red rooms can't be neighbors to themselves and the pathfinding algorithm doesn't go for diagonals, it should create a not so direct path from one node to the other.

For all nodes in the path, add their red, blue or green neighbors. This should add the possibility of side paths and overall complexity/difficulty in the dungeon.


Room Creation and Connection

Join smaller grids into bigger ones according to predefined room sizes. Use a higher chances for smaller widths/heights and lower chances for bigger widths/heights.

Generate all possible connections between rooms.

Randomly remove connections until a certain number of connections per room is met. If n = total rooms, then set n*a rooms with >=4 connections, n*b with 3, n*c with 2 and n*d with 1, such that a+b+c+d=1. Controlling a, b, c and d lets you control how mazy the dungeon gets. If c or d are considerably higher than a or b then there won't be many hub rooms that connect multiple different paths, so it's gonna have lots of different thin paths with dead ends. If a or b are higher then the dungeon will be super connected and therefore easier.

Reconnect isolated islands. Since the last step is completely random, there's a big chance that rooms or groups of rooms will become unreachable.

To fix that:

  1. Flood fill to figure out how many isolated groups exist;
  2. Pick a group at random and go through its rooms. For each room check if it neighbors a room belonging to another group, if it does then connect them and end the search;
  3. Repeat the previous steps until there's only one group left (everyone's connected).


END

And that's it, I guess. There's more stuff like adding special rooms, but that's specific to each game, so whatever. But basically I have a few parameters I can control when creating a new dungeon: dungeon width/height; percentage of hard, medium and easy rooms; what color neighbors get added to the original path and the percentage of rooms with >=4, 3, 2 or 1 connections. I think that's enough to have control of how easy/hard the dungeon will be...

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions