Skip to content
An algorithm that generates a level for roguelike games.
Python
Find file
Latest commit 804d6ef @mizipzor Update README.md
Link in credits is now broken, can't find a mirror, not sure what to do.
Failed to load latest commit information.
.gitignore Initial commit
LICENSE Initial commit
README.md Update README.md
dungeon.py Added code.

README.md

roguelike-dungeon-generator

An algorithm that generates a level for roguelike games.

There's also a C# port.

Outline

  1. Divide the map into a grid of evenly sized cells.
  2. Pick a random cell as the current cell and mark it as connected.
  3. While the current cell has unconnected neighbor cells:
    1. Connect to one of them.
    2. Make that cell the current cell.
  4. While there are unconnected cells:
    1. Pick a random connected cell with unconnected neighbors and connect to one of them.
  5. Pick zero or more pairs of adjacent cells that are not connected and connect them.
  6. Within each cell, create a room of random shape.
  7. For each connection between two cells:
    1. Create a random corridor between the rooms in each cell.
  8. Place staircases in the cell picked in step 2 and the lest cell visited in step 3ii.

Example output

         ######                    ############# ######
######## #....#         ########   #...........###....#########
#......###....###########......#   #...##.......##............#
#..............##......##......#####...##.............###.....#
#......##......##......................##......###....# #.....#
#......###.....##......##......##########......# #....# ####.##
#......# #.....##......#########        #......# #....#   #..#
####.### #####.#####.###                ######## ###### ###.##
  #..#       #.#####.## ######          #####           #...##
 ##.####   ###.##.....# #....#          #...#         ###....#
 #.....#   #..........# #....############...#      ####......#
 #.....#   #...##.....# #..............#....#      #....#....#
 #.....#   #...##.....# ###.######..........#      #...##....#
 #.....#   #...##.....#   #.#    #.....####.#      #...##....#
 #.....#   ############   #.#    #.....#  #.#    ###...##....#
 #####.#                  #.###  #######  #.#    #...######.##
   ###.# ######         ###...##        ###.##   #.###   ##.###
   #...# #....#  ########......#        #....#  ##.##### #....#
   #...###....#  #.....##......##########....#  #......# #....#
  ##...##.....#  #.....##......##......##....#  #......# #....#
  #...........####.............##......##....#  #......###....#
  #....###.............##......##......##....#  #.............#
  #.#### #....####.....##......##............#  ##########....#
  #.#    ####.#  ##################.##########           ##.###
  #.#    ####.## ######           #.####                  #.#
  #.#    #.<...# #....##########  #....#                  #.####
###.##   #.....###.............#  #....######### ######   #....#
#....#   #.....##.....##.......#  #............# #....#   ##...#
#....#####.....##.....##.......#  #....###.....# #....######...#
#..............##.######.......#  #....# #.>...# #.............#
##.#######.....##.#    #.......#  ###### ####### #....######...#
 #..#    ########.#    #####.###                 ##.###    ##.##
 ##.####        #.######   #.#   #######         ##.##     ##..#
 #.....# ########......#####.#   #.....#         #...#     #...#
 #.....###.............##....#   #.....#         #...#     #...#
 #..............#......##....#####.....######### #...#     #...#
 #########.....##......##......................###...#     #####
         #.....##......##...#############............#
         ########......######           #......###...#
                ########                ######## #####

Credits

Created as I reworded this algorithm (link is now broken, can't find a mirror) to make it easier to follow.

Something went wrong with that request. Please try again.