Procedural generation

10

In games like minecraft, cube world and starbound there is the term "Map procedurally generated". As you walk during the game, the map is created, but with a "seed" that will always generate the same map. >

How can you use a small set of characters to determine the creation of standard maps, with hills, hawks, ores and other features always in the same place (based on the same seed)?

    
asked by anonymous 02.07.2014 / 19:52

2 answers

6

Basically game developers when using Seeds, they use Hashes generators.

Hashes Generators: Generate the same sequence of characters based on a short word.

With the generated hashes they can generate other threaded hashes that will define other points of the game equal to the seed

For the generation of maps and reliefs, the algorithm that I saw the most was Perlin noise , which also generates the same relief based on a seed and this was also the algorithm originally used in maps by creator of Minecraft.

How to create a hash generator? At first it is relatively simple, since it must always generate the same result based on the same input value, it can be a simple mathematical function.

For example, a hash logic using numeric seeds could be: seed = (seed x 31337) + 123

Example Hash Algoritmn (English)

    
02.07.2014 / 23:37
6

Attention: This is not a response, just a complement to Rogerio Barreto's answer.

Practical example of procedural generation using seeding :

var seed = 25; //Escolha um valor numérico positivo e inteiro qualquer.

var canvas = document.getElementById('mycanvas');

    if (canvas.getContext){

        var ctx = canvas.getContext('2d');

        ctx.beginPath();
        ctx.moveTo(0,100);

        for (var i = 0; i < 100; i++) {
            //Vamos usar a fórmula do Rogério Barreto
            seed = ((seed * 31337) + 123) % 100;
            ctx.lineTo(i * 10, 100 + ((seed - 50) / 5));
        }

        ctx.lineTo(1000, 200);
        ctx.lineTo(0, 200);

        ctx.fillStyle="green";
        ctx.fill();
    }

Result for different values:

25
19
91

Play with this code in JSFiddle.

    
29.08.2014 / 21:59