ID:40081
 
Keywords: demo, maps
An alternative to the previously mentioned method of generating an archipelago by Gughunter is to use cellular automata.



The steps are outlined below:


Step 1: Fill the map with water.

Step 2: Loop through each tile, and there is a 50% chance (you can make this any chance you'd like) that this tile becomes a land tile.

Step 3: Create a 2D list the same size as the map, holding whether or not the specific turf at each element in the list is land or water (don't store the actual turf, just 0 for land and 1 for water, for instance)

Step 4: Loop through the map again. For each turf, count how many turfs (including the center turf) that are around it that are land (not water). If there are 5 or more land turfs surrounding it, then that turf becomes land (or stays land if it already is land).

Step 5: Repeat step 3, 4 and 5 a specified number of times (the higher this number, the smoother the map becomes)



I hope you understood that. If not, try the demo (with source code) that I made here. Just compile and run, and wait for the map to generate.
Step 2: Loop through each tile, and there is a 50% chance (you can make this any chance you'd like) that this tile becomes a land tile.

If it's land, make all the tiles around it land too.
That's a lot of lists. For a 500x500 map, that's 501 lists. You can cut that number down to just 1 by using a list with a compound index. So, for example, if you want to access the Nth element of the Mth row, you'd use the compound index: N + M*(row_length - 1)

If you use multidimensional lists a lot, I'd suggest making a grid datum which handles these things for you.
If it's land, make all the tiles around it land too.

I don't think you'd want to do that during this step; you'd end up with nearly the whole map covered in land. After generating the archipelago, though, you might find it useful to randomly "grow" some of the islands.

I noticed you didn't mention anything about creating water.

I'm not sure the 5+ rule to stay land works though, because your land will rapidly vanish. That should probably be 5+ to become land, 4+ (or even 3+) to stay. Think about a coastline: If you have a jog in the coast, one land tile would be surrounded by 4 other tiles (as opposed to 5 for a straight edge). If that tile disappears, this effect will ripple along your coastline, making it vanish.

Chances are this kind of distribution will give you a lot of small islands though. The land-seed approach I think is really your best bet. Short of that, I'd probably try a fractal height field (pretty easy to do if you just have a big list of numbers) and then adjust the sea level as desired. You can even seed this, too, by creating a high point somewhere in the middle and low points near the edges.
That sounds totally like how I make maps in Wargames 2, except I've got some level of customisation to create different level of maps.

I actually have two stages at the end (that is, in the land+sea stage), one is de-islanding which focuses on getting rid of small areas of land, and then smoothing which makes the landmass more smooth and less blocky, but this can be customised into different levels with different effects.
I used a very very similar algorithm to generate maps in Conquest (aka Reach for the Stars).

The probability of becoming water was based upon input, and the cellautomata rules were slightly different.
Hmm, didn't think about using a fractal height map. I've used them to generate random terrain but the results were too random to trust. For instance, sometimes the entire map is land, sometimes the entire map is water, sometimes there is very very little water, and sometimes there is very very little land. It just wasn't very dependable.
Lummox JR wrote:
I noticed you didn't mention anything about creating water.

I'm not sure the 5+ rule to stay land works though, because your land will rapidly vanish. That should probably be 5+ to become land, 4+ (or even 3+) to stay.

Actually you'r right. It's 5+ to become land, 4 to stay. You can play with the different setting using my old http://www.byond.com/hub/Xooxer/Life3 cellular automata demo. I've found that checking the numbers 5,6,7,8 on the Born side (your land, I suppose), and only 4 on the Stay side, then a randomly filled grid will settle into the most appealing organic shapes. Playing with other settings can produce other effects that could be useful in game creation.
Koil wrote:
Hmm, didn't think about using a fractal height map. I've used them to generate random terrain but the results were too random to trust. For instance, sometimes the entire map is land, sometimes the entire map is water, sometimes there is very very little water, and sometimes there is very very little land. It just wasn't very dependable.

Well, I've got... no experience in this area whatsoever, but couldn't you rather simply check the percentages of land to water at the end, and if it's not acceptable, such as a % difference greater than 40%, (for example 75% to 25%, which has a difference of 50%) throw it out and start from scratch?
Throwing out results repeatedly is best avoided if you can help it. Tweaking an existing result is almost always preferable.