## How to create a Random Map Generator

Psyjax
Unregistered

Post: #1
Hey folks, I am trying to develope a random map generator in the same style as those seen in games like Civilization. I need to be able to control the amount of land, the number of continents, islands, etc.

I have tried several methods, using a linear aproach. But my results have never been that good. Either I lack to much controll, or the algorythim 'sticks' and producess ugly maps.

My map is a simple 2d array of int's, with one of two values. Water or land. How would I go about developing an efficient method for generating nicely formed, semi-realistic continents?
Moderator
Posts: 133
Joined: 2008.05
Post: #2
I've never really done anything like that, but I guess what I would try and do is something like this:

Generate n random pair's(x,y), where n is something like the width/15, more or less depending on how much land you want, and x and y are of course coordinates. Then at those coordinates set them to land. Then generate another random number called radius, and for each land speckle you plopped down before, create a circle around it with radius of the random number. But instead of making a "circle", add +/- 5 or some another small number to the radius each time you go out to get more of a natural look instead of smooth shoreline.

This, with a little tweaking of course, since I'm just going off teh top of my head, should work. It will also create joined continents to give even more interesting shapes.
Member
Posts: 78
Joined: 2002.06
Post: #3
Have a look at the free-civ source code. It includes several methods. http://www.freeciv.org
Member
Posts: 45
Joined: 2002.04
Post: #4
well, when you say you want something like Civ, I also think of Age of Empires and things of that nature that have random map generators.

You take the approah of "Rooms" "Hallways" "Random Places".

what I mean by that is, have 1 function that creates a set of large Continents, just big chunks of of the map that have no initial spot in the world map, but are already shaped.

another function would randomly place this pieces into the world map.

a thrid function would create the "hallways" or the links between continents, ie: land routes, passable ocean.. whatever land type allows movement between "Continents". These would be created like the continents, but placed directly into the map so as to allow the linking to happen properly..

then you could have random function that just creates entirely random spaces that are placed in random spots and are not overlapping the continents or the sections you've already made.

you could store those all in a linked list temporarily then integrate them into your map data.

sounds a bit complicated but I believe it will produce nice maps for ya...

/* Drunk...... fix later.... */
Moderator
Posts: 365
Joined: 2002.04
Post: #5
What about writing a cellular automaton to 'grow' the landmass? Drop several automata into the sea, and have them change the sea to land wherever they move. If you program them to crawl around the edge of existing land in a random direction, you should be able to generate some quite interesting organic-looking shapes.

Neil Carter
Nether - Mac games and comic art
Psyjax
Unregistered

Post: #6
Wow! YOU guys have really given me some great food for thought. Great Ideas folks! Keep em coming

So far, I have been doing a sort of variation the room method mentioned above. Except that I designate one huge rect to be a continent. Then a recursive function comes thrugh and "bites " off pices to give it a coastline.
Diplomtennis
Unregistered

Post: #7
you could also use the approach of generating fractal plasma peril noise or whatever and then transforming the heightmap into your tile-map. This is especially interesting if you have more than "Land" and "water" tiles. e.g. Tiles wich are higher are "mountains", tiles wich are lower are "grass" and in between is "forest" or so...

here are two more interesting links:

http://www.roguelikedevelopment.org/~rog...tegory=MAP

http://astronomy.swin.edu.au/~pbourke/ (great website but mostly 3d mapping)

have fun.
Programmer
Unregistered

Post: #8
I was playing with an interesting "planet generator" algorithm a couple of years ago, and it could probably be adapted quite well to 2D maps. The idea was that you start with a sphere of the average radius that you want your planet to be, and then you repeatedly choose a random plane which slices the planet. Everything on one side you raise slightly, everything on the other you lower slightly. Do this enough times and you end up with some really believable looking planets. On a 2D map you could just choose a random 2D line through the map.

Another possibility is to just generate a map of completely random values and then repeatedly apply a variety of smoothing filters to the image. If you just use an averaging filter you'll generally end up with a fairly uniform gray, but if you alternate between a few others you can get some interesting effects.
Diplomtennis
Unregistered

Post: #9
Thanks, that is a good algorithm. I wrote a little program with it that can be found here:

http://home.arcor.de/Diplomtennis/mapmaker.sit
davidpk212
Unregistered

Post: #10
Try something like this:

Select a random point at the map, then employ Dijkstra's algorithm to continue expanding the "island" you have generated. Have an equation like (20 - number of times we've expanded) to calculate whether the algorithm should stop expanding at that particular point. When that is done, continue doing it, rasing up land further if the nodes collide.

This might generate very square looking map, and depending on how good your random number generator is, you might not find it particularly random, but it should do.

(I would love to be able to think of something I could use this for.)