I worked on random map generation over the weekend. I originally had a simple terrain generator where I just randomly turned a number of squares impassable to create a few obstacles. There was no pattern or thinking behind this and the terrain rarely linked together and made much sense.
So I decided to revamp that. My algorithm now works roughly as follows:
1. Start with a blank map;
2. Pick a random starting point;
3. Draw a line of impassable tiles from that point to another nearby point;
4. Repeat 3 a number of times creating a kind of skeleton of a mountain range in different shapes;
5. Repeat from step 2 a number of times so that there is a few different "skeletons" spread throughout the map;
6. Loop through the map, removing unlinked squares and growing those "skeletons" by way of an algorithm based on cellular automata;
7. Finally, flood fill the map to see if there are any unreachable tiles, perhaps isolated inside a mountain, and if so, fill them.
I'm pretty happy with the results with the line drawing part of the algorithm in particular creating some interesting landscape formations. It seems to regularly produce long mountain ranges with nooks and crannies which effectively are caves. And along with the new terrain generator, I included the ability for the player to choose their initial starting position so you have the choice as to whether you want to take advantage of these caves and base yourself there or whether you'd prefer to build out in the open. One unintended side effect of this is that my pathfinding cost has risen quite a bit so that might need to be reconsidered if it proves to be a huge issue going forward.
Here's a picture of what it looks like:
Next up I think I want to work on rivers and ponds, perhaps even with a very similar algorithm but with longer lines involved so that there are a big stretches of straight water which periodically turn.