Awesome
roguelike-dungeon-generator
An algorithm that generates a level for roguelike games.
There's also a C# port.
Outline
- Divide the map into a grid of evenly sized cells.
- Pick a random cell as the current cell and mark it as connected.
- While the current cell has unconnected neighbor cells:
- Connect to one of them.
- Make that cell the current cell.
- While there are unconnected cells:
- Pick a random connected cell with unconnected neighbors and connect to one of them.
- Pick zero or more pairs of adjacent cells that are not connected and connect them.
- Within each cell, create a room of random shape.
- For each connection between two cells:
- Create a random corridor between the rooms in each cell.
- 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.