Dungeon Generator

Roguelikes are always fun so I decided to try my hand at random dungeon generation. The generation process has three steps. First, I make a maze out of the dungeon area using a recursive backtracking algorithm. Second, I partially fill some of the dead ends to sparsify the corridors. Third, I place the rooms using a heuristic to avoid room overlap. (Exactly how I came across this algorithm I have long since forgotten.)

You can download the Java code and try it yourself.

Example

A 25-room dungeon. The at symbols (@) are walls, the dots (.) are corridors and the spaces ( ) are rooms.

@@@@@@@@@@@@@@@@@@@@@@@@@
@@@    @@@@..  .........@
@@@    @@@@.@  @@@@@@@@.@
@@@    @@@@.@  @@   @@@.@
@@@    @@@@.@  @@   @@@.@
@@@    .....@  @@@@...@.@
@@@@@@@.@@@@@@@@@@@.@.@.@
@@@   @.@...........@.@.@
@@@   @.@.@@@@@@@@@@@.@.@
@@@   @.@.@.........@.@.@
@@@   @.@.@.@@@@@@@@@.@.@
@@@@@...@.@.@@@    @@.@.@
@@@@@.@@@.@.@@@    @@.@.@
@    .@@@.@.@@@    @@.@.@
@    .@@@.@.@@@    @@.@.@
@    .@@@.@.....@@@@@.@.@
@@@@@.@@@.@@@@@.@@@@@.@.@
@    .....@@@  ..  ...@.@
@    @@@@@@@@  @@  @@@@.@
@@@@@@@@@   @  @@  @@@@.@
@@@@@@@@@   @  @@  @@@@.@
@@@@@@@@@   @  .@  @@@@.@
@@@@@@@@@   @.@.@@@@@@@.@
@@@@@@@@@   ..@.........@
@@@@@@@@@@@@@@@@@@@@@@@@@