Author Topic: Generate a Map with a seed  (Read 1811 times)

Offline BlackScorp

  • Level 16
  • *
  • Posts: 152
  • Reputation: +6/-0
    • View Profile
Generate a Map with a seed
« on: October 02, 2011, 08:48:37 AM »
Hey guys, today i saw a small sudoku game which was very interessting, becuase to create new sudoku map you used a "random seed" if you put the same seed everytime in, you would get the same numbers..

so basicly a sudoku map is similar to an RPG map. youve got areas and fields within the areas and each field has another number, you could call it as tile number or image number.. so i think it could be possible to store the seed in database and generate the map with the seed. it could save much space in the database because you dont save each tile and each position.

so my question is, what kind of algorythm is this seed generation? what have i google for to understand it how this maths works? or do you think it isnt possible to generate a map with those seed key? it works just for sudoku?

Best regards BlackScorp

Offline dbest

  • Game Owner
  • Level 20
  • *
  • Posts: 217
  • Reputation: +3/-0
    • View Profile
    • Tennis Masters
Re: Generate a Map with a seed
« Reply #1 on: October 02, 2011, 11:15:50 AM »
I believe you are looking for procedural map generation. You could start here: http://pcg.wikidot.com/pcg-algorithm:map-generation

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: Generate a Map with a seed
« Reply #2 on: October 02, 2011, 11:24:38 AM »
The seed is just used for random number generating.

When you use the same seed for your random number generator, it will always produce the same sequence of 'random' numbers.

So, if you have an algorithm for generating a map and pass the same seed to your rng, it will have the same result.

In PHP, you can use the srand function to seed the rand function: http://php.net/manual/en/function.srand.php

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,444
  • Reputation: +29/-1
    • View Profile
Re: Generate a Map with a seed
« Reply #3 on: October 02, 2011, 12:22:01 PM »
Random generating using a seed means that each time you call rand() function/s it will return exactly the same result.
Also, you don't need to store seed in DB, you can just arbitralily select a number, for example "1" :)

srand(1);
$a=rand();
$b=rand();
$c=rand();

No matter how many times you call this, $a,$b,$c will be the same combination each time.



In practice you would want to assign a separate seed for each grid on the map so it returns different terrain. The most primitive (and not the best looking) is srand($x+$y); (again, you don't need to store the seed anywhere since you make it from x and y of the grid).

Here a practical example of such terrain generator: http://www.worldoflords.com/misc/test/pnwmap/ (it also uses the distance modifier, so buildings farther from the center are more devastated).

« Last Edit: October 02, 2011, 12:24:23 PM by Chris »

Offline Ben Adams

  • Level 4
  • *
  • Posts: 13
  • Reputation: +2/-0
    • View Profile
    • Illyriad - Dev Blog
Re: Generate a Map with a seed
« Reply #4 on: October 02, 2011, 01:51:27 PM »
If you a doing it front end in JavaScript this is probably worth a read; since Math.random() doesn't let you seed it:  http://davidbau.com/archives/2010/01/30/random_seeds_coded_hints_and_quintillions.html
Currently working on Illyriad a real-time, HTML5 Massively-Multiplayer strategy game.

Illyriad - Dev Blog

Offline BlackScorp

  • Level 16
  • *
  • Posts: 152
  • Reputation: +6/-0
    • View Profile
Re: Generate a Map with a seed
« Reply #5 on: October 04, 2011, 03:06:07 AM »
no, you didnt undestood me.

my Idea was to save a map with a seed, so it should be possible to create a seed with an Editor. Actually everyone saves their map in Database or files, they save there an array where they get an result of x/y combination. my idea was , not to save each tile on each position, my idea was to save kind of math function.

for example in math you can say f(x) = x with this x you know every value if you know the y and x position


you just have the function and calculate the values you need. so you can see that math function as a seed. it would be possible to store the map, but it isnt possible to generate those seed(just spoke with a buddy who has Math Diploma, he told me that would be hard to calculate + you would get not everytime the same result its like MP3 compression you loose some data).. hope you understand me now better.

Greetings BlackScorp
« Last Edit: October 04, 2011, 03:12:24 AM by BlackScorp »

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,444
  • Reputation: +29/-1
    • View Profile
Re: Generate a Map with a seed
« Reply #6 on: October 04, 2011, 04:31:17 AM »
Quote
my Idea was to save a map with a seed, so it should be possible to create a seed with an Editor.
Impossible. The PHP/JS seed is limited to 4 billion combinations (2^32), that's not even nearly enough to include in this number of combinations all theoretically possible states one of them being you map. The seed lenght alone would most likely exceed the size of the map :) Plus, the current technological level of human race is completely insufficient for things like that (it would take billions of billions years to calculate this using all computers we have, and I suspect I'm still too optimistic :D).

It's basicly like saying "let computer randomly generate some letters and statisticly these will include all books written in the past and in the future". It is absolutelly correct from the statistical point of view, no doubt, but the number of iterations for this is way beyond insanity.

Offline arai

  • Level 10
  • *
  • Posts: 60
  • Reputation: +2/-0
    • View Profile
Re: Generate a Map with a seed
« Reply #7 on: December 16, 2011, 06:31:02 PM »
Quote
my Idea was to save a map with a seed, so it should be possible to create a seed with an Editor.
Impossible. The PHP/JS seed is limited to 4 billion combinations (2^32), that's not even nearly enough to include in this number of combinations all theoretically possible states one of them being you map. The seed lenght alone would most likely exceed the size of the map :) Plus, the current technological level of human race is completely insufficient for things like that (it would take billions of billions years to calculate this using all computers we have, and I suspect I'm still too optimistic :D).

It's basicly like saying "let computer randomly generate some letters and statisticly these will include all books written in the past and in the future". It is absolutelly correct from the statistical point of view, no doubt, but the number of iterations for this is way beyond insanity.

Impossible is too strong a word.  Besides, it sounds to me like he's just talking about a compression algorithm.  The problem with those is they can guarantee a given seed length (compressed data), or a given lossyness (accuracy of reconstituted data), but usually not both.  Additionally, achieving good performance on both of those fronts usually requires a specific investment in a codec designed to make the most of the nuances of the data being encoded (which is why you rarely see audio data encoded using lzma.)

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal