Creating great software, one line at a time


Quick level generation algorithm

Posted by Rowan Powell on July 18, 2015 at 5:00 AM

For my AI demo I needed a level for the player and the AI to face off inside which met a few simple criteria,

  • All places on the map can be reached from any other point
  • The map has a variety of open and more cramped areas
  • The map is complex enough in navigation that items have a reasonable distance between them and it's engaging to the player
After a bit of messing around with various approaches I was inspired to making something akin to this rougelike dungeon generator

So the algorithm I made has the following stages;
  • Generate some Room objects
  • Move them apart from each other so that they don't merge into larger rooms
  • Find rooms that overlap on an axis that don't have rooms between them that a connection would cross through
  • Make a connection between those rooms roughly in the centre of where they overlap on that axis
  • Put items and other decoration into the level
The creation of rooms and corridors naturally gives some smaller areas as well as any larger rooms, which works well for the type of level we want to create. but it is important that the rooms take up most of the space of our level, large empty gaps might mean we end up with unconnected rooms if they don't line up with any others. Rooms too spread out will also mean that the corridors become very long, which might work for singleplayer adventures but don't work very well when trying to find and engage in a 1v1 battle.

Categories: Summer 2015

Post a Comment


Oops, you forgot something.


The words you entered did not match the given text. Please try again.

Already a member? Sign In