Random Map Generation

Started by
24 comments, last by psyjax 20 years, 6 months ago
Hey folks, This is my first post here, so I''m not sure if this is the right section or not. In any case, I was wondering if anyone could propose a simple method for a random map generator, similar to those seen in games like Civilization. For my particular project, my map is stored in a simple 2D array of int''s, and I wan''t to come up with an effective way of generating nice sized semi-realistic continents. I have used several methods, but many of the ones I have come up with provide little controll. Is the key to this a linked list method as opossed to a scanning linear aproach? If anyone has any suggestions, or ideas please let me know. My prefered language is C if one would care to offer examples :D
Advertisement
I''ve have never done such a thing, but I can tell you how I would do it. First of all, linked lists would definitely not simplify the solution and would just complicate things. Leave it in a simple array. I don''t know exactly what you want on your map, but I''m assuming that you want something like trees, mountains, rocks and lakes (rivers would be too hard to implement). I''ll just use a mountain as an example (because its probably the most complicated). I''ll assume that you keep track of mountain tiles by storing their height. I would just choose a few random tiles and give them each a height of 1 or 2. Then I''d have a loop that executes a bunch of times (perhaps a certain predefined number of times, or until the map has reached a predefined average height), and each time all tiles that are adjacent to a mountain tile will have a random chance of increasing in height, the odds being better for tiles which are adjacent to heigher surrounding tiles.

I hope I explained well and that this was useful.
Zorx (a Puzzle Bobble clone)Discontinuity (an animation system for POV-Ray)
hmmmm....

Thanks alot, I actually didn''t give a height consideration to mountains. Actually, I''m starting out very simple. For the purposes of this thread, lets just say there are two tiles:

Water, and land.

I will consider the mountain thing thogh. It sounds like it could work! Hehehe

Any other suggestions for just, water and land tiles?
One option: Make subdivision plasma/multi-octave perlin noise, make every value above the halfway point water, and the rest land.

Another option, less realistic, but better than you might assume: Have an "ant" do a random walk on the water; wherever it goes turns into land.
make a random number (within set ranges) of ants with random starting locations (and they may or may not be allowed to start near each other), and then give them a random lifespan (number of steps).

So this algortihm has the following controllable areas:

- range for number of ants
- minimum distance for starting ant distance (can be 0)
- walking patterns, ie: completely random, or a disposition to either go in same direction or turn or whatever
- range of values for lifespan
- a bool deciding if "lifespan" is number of steps, or number of squares changed (so that walking over squares again doesn''t reduce total land)

I have no idea how this would turn out ... but I can see a very definate easy way to code it, which is a plus. After coded, play with a couple different sets of numbers, and see if any looks viable at all (BTW, print out the controlling parameters you test and at LEAST 5-10 maps of each type, to see how consitent or varied they are)

good luck.

Also, that perlin noise idea is cool ... basically, anything which works for cloud generation could be made to work for land generation, except remeber this, clouds form in a free 3d open space, where land form shapes due to techtonic shifts and fault lines ... and then errosion - so the perlin noise algorithms (and the random ones) will eventually want to be expanded and made more complicated in order to allow for more "grouping" of like tiles (also due to temperature), but still allow for abrupt shifts ... but that''s more advanced than you need right now.
I like the ants idea. I agree that perlin noise may be too complicated to get into. I mean, it''s just a 2d tile map for gods sake :D

In any case, I have done "ant" type algorithems before with some success. My major problem was lack of control. I got alot of "land-trails", these don''t look good on continents.

I belive I could perhapse confine the ants to a given region, like a large rect for one continent, etc. That would likely ensure more self contained land masses.

Perhapse, many ants with short life spans as you said will remediy the need for more coherent, self-contained land masses.

I think I will try and test this method first. Thanx for all the help!

If anyone else ahs suggestions, please let me know. I''ll keep you all updated.
if you like the ants idea, you'll love BlotchMaker, which is the map generator for my project:

http://www.project-axis.net/

feel free to download the current v0.1 demo to play with it, and download the entire source code for it if you want.

BlotchMaker has so many options, it's a science all to itself :-)

here's a screenshot:

http://www.project-axis.net/artbin/screens/snapshot22.png

the maps it makes aren't quite what you would get in a civ game, but you could easily get close with the right options (or very far away, alternatively). Basically, it relies on placing a certain number of one-after-the-other tiles in a series, with each tile's placement being randomly rolled for based on a series of "turn persuasion" which can make the "blotch" look like a straight line or continent depending on how you set it. It also supports "brush types", number of blotches, tiles per blotch, edge gravity, obstacle types (water, land, fort, whatever you program it for), deterioration, empty/filled reversal, and a slew of other options.

hope that helps a bit

[edited by - leiavoia on October 3, 2003 11:13:33 PM]
Well, I ended up takeing a rather novel aproach.

I randomly lay down a big square, this is the proto-continet. Then I scand the continent, any square that touches watter, has a 50/50 chance of beind ''deleted''. There is a sertain quota of tiles to delte, so the program scans back and fourth across the square untill the quota is met.

Make about 10 of these big blocks, repeat the steps above, and you got your self some nice looking land masses

Hope this aproach benifits anyone, who may dig up this thread in teh future. In the meantime, keep posting ideas. Im sure this will come up again.
It sounds like you''ve solved your problem- I like your erosion idea. Another possibility is fractal interpolation of class values (in your case, land and water). Subdivision of the grid would proceed as it normally does with the subdivide-and-perturb methods, but the interpolated values are random selections of the existing neighoboring classes. This method is described in "Real-World Fractals", by Mark Finlay, Keith A. Blanton and Keith Finlay (ISBN 1558513078).

One more height-map generator for all to consider is one presented in the July, 1994 issue of "Dr. Dobb''s Journal" (http://www.ddj.com/). The author''s Web page on the subject is here:

http://www.parse.com/~rk/fractal.html


This one uses repeated application of "fault lines".


-Predictor
http://will.dwinnell.com


You might want to invest into fractal noise generation. It may just be a "simple 2D tile landscape" but you ARE going for a rather broad approach. The best algorithm (and somewhat simplest) would be fractal clouds. With a few inital tiles (say, outlining a continent) you could come up with some very, very good results.

My advice is to have a 2D array of bytes (the screen works wonderfully, you can see it draw itself in real-time ;P) and generate a landscape based on pixels. Suppose you want a 50x50 map, create a 50x50 image. Then establish a range for every tile...

00-32 - Water
33-40 - Sand
41-90 - Grass
91-B0 - Forest
B1-FF - Mountain

You get the idea. The above would generate mountains only in the middle of forests but that''s just an example.

For reference''s sake, here''s a screenie of a rather quick and dirty landscape generated using a fractal cloud. You can get much more realistic results with perlin noise (the second picture) though. By the way, the second one is from an other program I coded to try out stereoscopic vision in 3D simulation; cross your eyes so the two landscapes overlap and you''ll see it in 3D :D But yeah, you get the idea.






This topic is closed to new replies.

Advertisement