Well, my current project is at a standstill, cause I need to do some more planning, so I've decided to do a little bit of work towards that tunneler remake project I sort of mentioned in the last post.
First thing I wondered was: "How did Geoffrey Silverton generate those maps?" Indeed, they are real nice, and they rendered quick, even on the limited hardware of the time. However, the levels generated by the old DOS Tunneler are always very similar, with all obstacles cleanly placed along the outer borders. I wanted maps in my version to be larger and more labyrinthine. So, after a bunch of experimentation, I came up with an algorithm that generates fairly interesting maps with high precision. The algorithm is 3-phase:
- Tree Generation: A bunch of random points are placed on the screen. Then, we repeatedly make edges between the two closest points which are in disjoint sets. This will generate a non-intersecting, and fairly natural-looking, tree. We then draw this tree, so that the following phases have something to work with.
- Random Growth: We iterate over every point on the screen, and any point that is bordering a point that has already been set may then get set. Over many passes, the structure will grow, and will eventually cross some threshold (in this case 62%) where we end this phase. Also, I linearly reduce the probability of points getting set along the borders, so that we don't have have caverns colliding with the borders.
- Cellular Automata Smoothing: Using a slightly altered version of Conway's Game of Life, we smooth out the graph. The rules have been altered so that outlying points will die quickly, and so that the entire computation will converge to a solution.

This isn't the quickest algorithm out there, but it's quick enough. The current version is written in Python, and it takes 14 seconds to generate a new graph. (Most time is spent on the random growth stage.) Once I'm more comfortable with the performance of the algorithm, I'll code it up it C, and hopefully we'll have a nice-n-speedy cave generator.
Any thoughts, btw? This is my first attempt at a random level generator, so it's probably not the best solution out there... But if you can do better, I'd love to see it, and possibly include it as a level option in this Tunneler clone. :)
Source Code (GPLv3)
