Wednesday, February 11, 2009

Procedural Content Generation

Procedural content generation is sort of a hip topic in both indie and mainstream games. If a game developer can generate assets from their code rather than designing assets by hand, that can save time and reduce the storage size of the game (on optical media or a hard drive).

For example, in the Diablo series, dungeons are pseudo-randomly generated. The benefits of this are two-fold. Players never see the same dungeon twice, adding replay value, and developers didn't have to go through and setup each dungeon manually.

I wanted to experiment with this concept. I decided to start as simplely as possible, a random maze generator. Algorithms exist for this problem and can be easily found via Google, but I decide to roll my own for my first try.

My maze generator basically works like this:
  1. Generate an m-by-n array of #'s (#'s denote and impassable tile)
  2. Randomly pick 2 tiles (a start and end point) and mark them "S' and "E" respectively
  3. Clear a path between the start and the end (replacing the #'s with .'s). My algorithm just starts at the start point and moves around randomly until it gets to the end point.
You've probably deduced this doesn't work too well.

Sometimes I generate decent mazes like:


Or:



Other times, I get something way too easy like:



So, what have I learned? Generating content purely randomly often doesn't work out too well. Also, random levels aren't that fun.

I'm going to try to implement a real maze building algorithm and see how that goes.

No comments:

Post a Comment