Seeded Generated Random Maps

I have a client - server situation where I need to generate maps. Rather than sending the entire map to the client I would simply like to send a set of numbers. The client would use these numbers to generate an identical map.

I need an aglorithm that does not need to generate the entire map before I can use it. I need a simple function that only takes a location, e.g.

getTerrain(x,y);
getVegetation(x,y); // would return an integer representing a plant

I need some help, as I don’t know where to start. Can this be done?

you could use Perlin Noise
http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

I use it for many things like terrain generation, movement paths, textures,…
You need just a few numbers to generate a mostly endless map
:slight_smile:

I looked at the article and I think I can use the 1 dimensional and 2 dimensional noise he is talking about. Just a small routine question. Is there a Java Perlin Class? I do not want to re-invent the wheel if it is available by a better programmer than myself. :slight_smile:

http://potatoland.com/blog/text/meander/PerlinNoise.java

I went to this site:
http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

And implemented a 2D noise function:
public static double intNoise2d(int x, int y){
int n = x + y * 57;
n = n << 13 ^ n;
return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}

This gives me values between -1 and 1, which is enough for me. I can generate terrain and trees etc. based on the numbers it gives me.

My question is, how do I seed it? Now it will give me the exactly same map each time. ;D

just vary the numbers…

  • make an offset
 public static double intNoise2d(int x, int y){
  x+=100000;
 y+=evenmore
int n = x + y * 57;
  n = n << 13 ^ n;
     return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);  
 }

or

  • change the 57 to a bigger prime
  • change the numbers in the brackets (15731 to another prime)
    not very difficult :wink:

This might be very interesting, especially for the 4k java competition.

You could skip defining map data in some text file, and simply define seeds for the levels/maps.