Procedural generation

Asked

Viewed 2,117 times

10

In games such as Minecraft, Cube world and Starbound there is the term "procedurally generated map". As you walk through the game, the map is created, but with a "Seed" that will always generate the same map.

How is it possible to use a small set of characters to determine the creation of standardized maps, with hills, havinas, ores and other Features always in the same location(based on the same Seed)?

  • Cool question. : ) You were inspired by this thread in Gamedev? http://gamedev.stackexchange.com/q/18840/36442

  • 1

    What did you mean by small character set? Generally procedural maps are generated with Perlin Noise, or other algorithms that always give the same result when fed the same variables (in addition to Seed). You can use different algorithms, or the same result use different pieces of information to determine the height of the terrain, the material, whether it has a tree or not. "Mobile" things like water, depend a little on you store data if you want some kind of persistence (the user moves the scenario and finds things as left).

  • @Luizvieira I still do not follow the stack in English.

2 answers

6


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

Hash Generators: Generate the same string based on a short word.

With the generated hashes they can generate other chained hashes that will define other game points equal to the seed (Seed)

For the generation of maps and reliefs the algorithm that I saw most used was the Perlin Noise, that includes generates the same relief based on a Seed and this was also the algorithm originally used in maps by the 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)

6

Attention: This is not an answer, 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 inserir a descrição da imagem aqui
19 inserir a descrição da imagem aqui
91 inserir a descrição da imagem aqui

Play with this code in Jsfiddle.

  • 1

    Very good example ! Good to see you here my dear ! Hug!

  • 1

    @Rogeriobarreto I can say the same! Hugs! =)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.