Documentation and implementations of a recursive procedural generation algorithm authored by Christopher Ravosa.

Overview

Recursive-Dungeon-Generation

This repository contains implementations of a recursive algorithm, authored by Christopher Ravosa, for generating dungeons on a matrix. The general idea with this algorithm is that a dungeon is created by snaking paths out of a starting room known as the "origin" of the dungeon. Check back in the future to see implementations of this algorithm in different languages and with different modifications. For a more detailed overview of the algorithm, see the below sections.

Table of Contents

Quick Links to Implementations
Algorithm Summary
Visualized Example
Pseudocode
Acknowledgements

Quick Links to Implementations

Algorithm Summary

The algorithm works by placing a "room" object in an arbitrary position on a two-dimensional matrix. The algorithm then flips a coin on each door associated with the initial room object to determine whether it will open and attach the current room to another room in that direction. In the event another room is placed, the new room is instantiated with an open door connecting it to the previous room. Before the rest of the doors in the initial room are handled, the algorithm recursively calls itself on the new room, handling the new room's doors first. This process continues until there are no more opportunities for a room to instantiate off of an existing room. This can mean the path has reached the end of the map, that another room already exists in the desired pathing direction, or that the algorithm determined not to place a room in a given direction at all.

In all cases, the coin flip occurs prior to a room being placed or a connection being established between a new room and a pre-existing room. This means that simply because two rooms are adjacent to each other, does not mean they will always connect. This creates a maze-like structure and ensures that all rooms are reachable from the initial room placement known as the "origin".

There are many modifications which can be made to this algorithm. For example, the algorithm can be modified to work on a three-dimensional array of rooms with six doors. The fifth and sixth doors would exist on the floor and ceiling, effectively creating the potential for stairwells to exist. This modification allows seperate floors to exist in the dungeon. Other modifications include requirements regarding a minimum number of rooms or how frequently a room can be instantiated in a specific direction. The documentation of this repository, however, will exclusively discuss dungeon generation using this algorithm on a two-dimensional matrix.

Visualized Example

Christopher Ravosa's Recursive Dungeon Generation algorithm visualized in a gif

Pseudocode

The algorithm makes use of a Room class. Room defines an object containing a coordinates array to represent the object's position in the game world, and a doors array of four (4) booleans. Each boolean represents one (1) of the four (4) doors which may exist on each of the walls of a standard room. Each index of the doors array must be associated with one of the cardinal directions. For example, 0 -> North, 1 -> East, 2 -> South, 3 -> West. If a boolean in the doors array is true, that means the associated door exists and attaches this instance of Room to another instance of Room in the direction associated with that index of the doors array.

This algorithm generates a dungeon (game world) on a matrix containing instances of the Room class. The matrix can be characterized by the dimensions n x m, where n is a non-zero row length and m is a non-zero column length. This algorithm works on both square matrices and matrices where row and column lengths differ. Included below is a pseudocode representation of this algorithm before any modifications have been made for generating more diverse dungeons.

generateDungeon(Int n, Int m)
   initialize the matrix, worldMap, which will be returned
   place a room, origin, in the matrix
   pathify(origin)
   return worldMap

pathify(Object room, Matrix worldMap)
   for each door in this room
      generate a percentage x between 0 and 100
      if x >= 50%
         set this door to true to open it
         if the adjacent spot in that direction on worldMap does NOT have a room
            place a room, newRoom, on that index of the matrix
            pathify(newRoom)

Acknowledgements

This list contains links to resources which were helpful in the development of this project:

  • Piskel: Used to create algorithm visualization
You might also like...
๐Ÿ”ฅThe Android Startup library provides a straightforward, performant way to initialize components at the application startup. Both library developers and app developers can use Android Startup to streamline startup sequences and explicitly set the order of initialization.
๐Ÿ”ฅThe Android Startup library provides a straightforward, performant way to initialize components at the application startup. Both library developers and app developers can use Android Startup to streamline startup sequences and explicitly set the order of initialization.

๐Ÿ”ฅThe Android Startup library provides a straightforward, performant way to initialize components at the application startup. Both library developers and app developers can use Android Startup to streamline startup sequences and explicitly set the order of initialization.

A simple (and naive) RESTful API made with Ktor, jasync-sql and JWT.

A simple (and naive) RESTful API made with Ktor, jasync-sql and JWT. Route Method Description /account POST Create a new account /account DELETE Delet

High performance and fully asynchronous pulsar client with Kotlin and Vert.x

pulsarkt High performance pulsar client with Kotlin and Vert.x Features Basic Producer/Consumer API Partitioned topics Batching Chunking Compression T

An application to follow popular movies and tv series and create watch list

MoviesAndTV MoviesAndTV is an application to follow popular movies and tv series and create watch list from your favorite tv series and movies. Also y

Clean MVVM with eliminating the usage of context from view models by introducing hilt for DI and sealed classes for displaying Errors in views using shared flows (one time event), and Stateflow for data

Clean ViewModel with Sealed Classes Following are the purposes of this repo Showing how you can remove the need of context in ViewModels. I. By using

An Android app that calculates BMI values and results by entering your height and weight
An Android app that calculates BMI values and results by entering your height and weight

BMICalculator BMI ์ง€์ˆ˜๋Š” ์†Œ์ˆ˜ ํ•œ์ž๋ฆฌ๊นŒ์ง€๋งŒ ์ถœ๋ ฅ๋จ BMI ๊ฒฐ๊ณผ์˜ ์ƒ‰์ƒ์€ ํ•˜๋‹จ ์ด๋ฏธ์ง€๋ทฐ์˜ ์ฒดํ˜•๋ณ„ ๊ฒฐ๊ณผ๊ฐ’์˜ ์ƒ‰์ƒ๊ณผ ๊ฐ™์Œ ์ฐธ๊ณ ํ–ˆ๋˜ ๋งํฌ

Microservices-demo - Microservices demo project using Spring, Kotlin, RabbitMQ, PostgreSQL and Gradle and deployed to Azure Kubernetes Kafka-hot-and-cold-retries - Demo project for elaborating how hot and cold retries can be applied in Kafka
Kafka-hot-and-cold-retries - Demo project for elaborating how hot and cold retries can be applied in Kafka

Apache Kafkaยฎ - Hot and Cold Retries A demo project for elaborating how hot and

A POC for spring app using testng, cucumber, findbugs, and jacoco framework with failsafe and surefire plugins.

A POC for spring app using testng, cucumber, findbugs, and jacoco framework with failsafe and surefire plugins.

Owner
Christopher Ravosa
"After all, the essential point in running a risk is that the returns justify it." - Isaac Asimov, Foundation and Empire
Christopher Ravosa
๐ŸŽ“ Learning Kotlin Coroutines for Android by example. ๐Ÿš€ Sample implementations for real-world Android use cases. ๐Ÿ›  Unit tests included!

Kotlin Coroutines - Use Cases on Android ?? Learning Kotlin Coroutines for Android by example. ?? Sample implementations for real-world Android use ca

Lukas Lechner 2.1k Jan 3, 2023
GraphQL Jetpack - A collection of packages for easily writing Java GraphQL server implementations

GraphQL Jetpack A collection of packages for easily writing Java GraphQL server

Ryan Yang 18 Dec 2, 2022
RCZ algorithm in kotlin (update version)

RCZEncryptationKT RCZ Encrypt uses maps to encrypt your string this use ALPHABYTE to to view the bytearray of encoded strings This use random chars by

Halq 5 Oct 11, 2022
Jetpack Compose for Desktop and Web, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.

Jetpack Compose for Desktop and Web, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.

JetBrains 10k Jan 7, 2023
A counter down timer for android which supports both dark and light mode and Persian text and digit.

FlipTimerView A counter down timer for android which supports both dark and light mode and Persian text and digit. English Perisan Getting started Ste

Arezoo Nazer 7 Jul 17, 2022
Quick photo and video camera with a flash, customizable resolution and no ads.

Simple Camera A camera with flash, zoom and no ads. The camera is usable for both photo taking and video recording. You can switch between front and r

Simple Mobile Tools 644 Dec 26, 2022
This Kotlin Multiplatform library is for accessing the TMDB API to get movie and TV show content. Using for Android, iOS, and JS projects.

Website | Forum | Documentation | TMDb 3 API Get movie and TV show content from TMDb in a fast and simple way. TMDb API This library gives access to T

Moviebase 37 Dec 29, 2022
Kotlin microservices with REST, and gRPC using BFF pattern. This repository contains backend services. Everything is dockerized and ready to "Go" actually "Kotlin" :-)

Microservices Kotlin gRPC Deployed in EC2, Check it out! This repo contains microservices written in Kotlin with BFF pattern for performing CRUD opera

Oguzhan 18 Apr 21, 2022