You are here: Re: Random Map Generation « PHP Programming Language « IT news, forums, messages
Re: Random Map Generation

Posted by Toby A Inkster on 02/15/07 17:16

skulkrinbait@googlemail.com wrote:

> My first prototype for doing this doesn't give good results, the map
> being far too random, can someone help me out or point me to a good
> resource please?

Real geography is not random.

First, take a grid, say 1001x1001 is size. Now find the middle square of
it and set it to have a height of 1m above sea level. Now spiral out from
that square, creating a height for each square using an algorithm like this:

1. Look at the adjacent squares, but only the ones that
you've already assigned a height to!
2. Find the average (mean) of height those and call it $h.
3. Now here's where we add a bit of randomness:

if (rand(1,2)==1)
$h -= log(rand(1,1000000));
else
$h += log(rand(1,1000000));
if (rand(1,20)==1) $h *= 3;

There is a note way down below about step 3. Don't read it yet. Wait until
you get there.

OK. Now you have a 1001x1001 grid of various heights. Anything below 0m in
sea level should be water.

Find the two highest grid squares. Make them and the adjacent 16 squares.

Find the four next highest which aren't already covered with ice. Add
rivers flowing from them. Here's how you chart a river's course from its
origin.

1. You're on a particular grid square.
2. Are you at the sea yet? If so, stop.
3. Look at the 8 adjacent squares. Which has the lowest altitude?
4. The river should flow to that square. Go to step 1.

Now you know where all the water is, find the ten squares furthest from
any rivers, ice and ocean. Make them into desert.

Find areas that are between 12m and 25m above sea level and are not
either ice, river or desert. Make them into forest.

Select a random two of the four rivers. Place a city where they meet the
sea.

Select a random two of the four rivers. Place a city half-way between the
origin and the sea.

Place two cities at any random part of the geography that is not under
water.

You get the idea. For any other geographic feature, you should be able to
think of a method of placing it randomly, but realistically.

Having done all this, you might realise that your map is now either too
boring, or too unrealistic. So here comes my note about step 3. Most of
the randomness that is introduced into the map is introduced here:

if (rand(1,20)==1) $h *= 3;

If you want to make it more random, then either decrease '20' or increase
'3' (or both!). If you want to make it more boring, then do the reverse.

I'd be interested to see how it pans out, and how much use any of my ideas
are. Please do post here, or drop me an e-mail when you're done.
mail at tobyinkster dot co dot uk.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация