πŸ—ΊοΈMap generation R&D

In this section we will explain the process behind the map tiles generation. Skip it if you just want to play the game πŸ€“

The algorithm used on-chain to generate the world as Apinators are roaming around has been created through a research process briefly explained bellow.

First is a simple example of random steps for the level determination of a land.

At every step a new level is calculated randomly depending on the previous one. This simple solution allows "control" for a not to steep level difference between neighbors but still a rather good looking level distribution. This solution is also really easy to compute, which is a big deal on-chain.

This solution by itself doesn't solve much as it's only working on a one-dimensional space. Using it on our 2 dimensional world would make it's level distribution look like bellow example.

To make this work we need to tweak the algorithm for a 2 dimensional application. After a little coding this is what our level distribution example looks like.

This example looks great but clearly still shows a big directional bias, like our previous one.

This bias doesn't mean our algorithm is broken, as it's due to the way we "walk" on our world. Actually, for simple implementation of our research tests we generated those world examples by applying our algorithm land by land, line by line, the same way we read words on a book.

For a better insight of what the world could look like with actual player walking on it and discovering lands one by one, we created a simple random walker algorithm. The walker is moving on the map from the center in random directions.

Bellow are two example level distributions using multiple random walkers.

As you can see those two distributions are pretty different. This is because they show two possible extreme cases in our world generation. The first one imitates a few players exploring very far away (small amount of random walkers, huge amount of steps). The second imitates the case with a big amount of players staying not that far from the starting point (huge amount of walkers, small amount of steps).

In reality we expect to get a distribution somewhat in between of those two cases.

On-Chain Implementation

Off-chain experimentation being acceptable, we can start working on-chain.

The 1st difficulty now is generating the random number requested at each land discovered. For the sake of our works speed, we start with a basic solution for this.

    function getRand(uint256 mean, uint256 max) private view returns (uint) {
        return uint(keccak256(abi.encodePacked(block.timestamp, block.difficulty, mean, max))) % 10;
    }

We can now check the look of a resulting on-chain world with this solution. To do this first simulate a "perfect" map discovery, with a spiral movement of one lonely walker.

This looks good, a real topographic shape is being generated on-chain.

Of course, as said earlier, the potential look of the real world roamed by real players will be closer to the one generated with random walks.

Upper image is a final example of procedural level generation fully on-chain with many random walks.

Please note that the game is going through further testing and balancing. The world generation is especially subject to changes.

The actual way of generating randomness could be different in the futur. We plan to use Chainlink VRF or a solution of our choosing.

Last updated