# 2D Island generator algorithm - chances of tile becoming land

I am developing my first island generator (in c#). I am using this algorithm as my basic idea : http://www.funstormgames.com/blog/2012/09/procedural-island-generation-for-ludum-dare-24/

Basically you loop around the tiles in a spiral shape, adding land based on chances - the more land the current tile is touching, the more chances of this tile becoming land. However, I don't know how to work with the chances - whatever I put I am never satisfied with my result.

If you havent worked using this algorithm, you can't really help me with the numbers, but a recomendation for a new approach would be great!

I am using a function to determine each tile - passing an argument called potentialChance. For the first "circle" or round around the starting island I put a 25 potential chance.

This potential chance was at first multiplied with the number of land tiles the current grid we are potentially changing into land is touching. So, if a grid has 3 surrounding tiles of land, its chance would be 75% (I generate a random number up to 100 and compare).

I was not satisfied with too many islands I got, and I was changing the potential chance while testing. So instead of multiplying the number of tiles with the potential chance - I tried a different approach.

I would have a quotient of ie 0.7, and for each surrounding land tile, I would multiply the quotient by ie 1.5, and then multiply that number with the potential chance. Still, I was not too satisfied.

I know my algorithm works properly (I have debugged and seen the results), but my numbers are not too good.

If anyone worked with this same logarithm, I would love to see the approach and numbers! Otherwise, would you suggest working on a new algorithm? I'm new in game development so...

-
Probabilities multiply faster than one might intuitively expect. Try your algorithm again, but move the parameter percentages by just 1% up or down at a time. Once you get close to what you want, scan again with perhaps a delta of 0.25%. Also, run each test at least twice, in case the first run hits an outlier. – Pieter Geerkens Jul 29 '13 at 2:22
What did you not like about the output? Are the islands to rough, to big, to small? – stonemetal Aug 27 '13 at 20:57

Both of these ideas require a test bed that lets the program run over and over with different parameters fed into it at each iteration:

If you want a "really out there" idea build a little genetic algorithm that works with your parameter set and let it run; at each result give the genes a Yes or No, eventually you'll approach something you like =)

Alternate version of the genetics would be to set all the parameters randomly, then as before give each iteration a Yes or No. Keep track of parameters that get more Yes and limit the randomness to nearby values, and so on.

Either would let you exhaust the possibilities of your current algorithm fairly quickly to help you decide on a winner or to move on to another procedure.

-

You could try to build your own algorithm around Perlin-Noise, it´s basically an algorithm used to create random shapes which look somewhat like clouds and is often used for random terrain generation (heightmaps).

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series4/Perlin_noise.php
(XNA and C# and in this case not utilised for your problem, but it still explains the Idea, i recommend to do some research on the topic on your own)

If you create the random map in a smart way and tweak all the parameters for the noisemap generation and maybe apply a mask to make sure you wont have any land on the edges of your map you will come up with a great island shaped map.

Perlin Noise might seem hard to control but in fact you can define the outcome very well if you know what youre doing. Just play with the factors for each scale of the map and see what gives you the desired results. You can allways do some non-random tweaking for example making values close to the center of the map generally higher then those close to the edges or calculate an exponential function for every value in the noisemap to get sharper edges, which might be a good thing in your case.

The next step will be to actually create the diffrent locations for the tiles from that map, but that shouldn´t be too hard. One way would be to say that every tile with a noisemap value lower than e.g. 0.1 is water and everything above is land. Very high values around 0.9 can be mountain rocks or whatever you may need, you will have to work out the details yourself here, it really depends on what you need. For things like forrest you can create one noisemap that generally defines where land and where water is and then a second which defines where forrest is, then multiply both together and you have a nice noisemap within your islands area.

These are just some ideas, there are plenty of ways to do this, just learn about perlin noise and see what works best in your case, Good Luck!

-
I don't think this can be expected to be useful. OP is satisfied with the current algorithm, and asks for help in setting the parameters; you respond by suggesting a new algorithm, for which OP would still be stick trying to tune the parameters, except for a more complex engine with more complex tuning. – Pieter Geerkens Jul 29 '13 at 2:19
Height maps as described here are probably more intuitive to tweak, but Perlin noise might be a bit daunting for a beginner. Another noise algorithm that is dead simple is midpoint displacement: code.google.com/p/fractalterraingeneration/wiki/… – Omokoii Aug 27 '13 at 22:34