Ores with high clust_scarcity

For people working on the C++ code.
Post Reply
User avatar
Tomas Brod
Member
Posts: 34
Joined: Thu Sep 18, 2014 13:57
In-game: Brod
Location: Slovakia
Contact:

Ores with high clust_scarcity

by Tomas Brod » Post

I propose an improvement to current ore generator.

Currently it is possible to define how often a cluser of ore can spawn. Internally, mapchunk volume is divided by this number to determine how many attempts to spawn ore should be performed in the currently generated chunk. But what if you specify higher scarcity and the number of ores in a chunk approaches zero? Currently it is rounded down to 0 (or 1 idk). Instead a random number r € R u (-1;+1) should be added to the result of the division and then rounded to nearest integer. This would enable extremly rare ore deposits. The pseudocode is for illustration and assumes / is operator for real division.

Code: Select all

NumberOfClusters := Round( (ChunkVolume/ClustScarcity) + (Random(-100,100)/100) );
I am not good at single-letter languages. Considering the simplicity of the code, this should be fast to implement and also fast to execute with arithmetic coprocessor.

Edit: typo.

User avatar
Gael de Sailly
Member
Posts: 845
Joined: Sun Jan 26, 2014 17:01
GitHub: gaelysam
IRC: Gael-de-Sailly
In-game: Gael-de-Sailly gaelysam
Location: Voiron, France

Re: Ores with high clust_scarcity

by Gael de Sailly » Post

+1.

I may say exactely the same thing, maybe I've not understood exactely what you say.
  1. Calculate the average number of clusters in the chunk (for example if clust_scarcity = 50*50*50 = 125000, this number is 512000 / 125000 = 4.096)
  2. Add a random float number between 0 and 1. So, we have a number between 4.096 and 5.096
  3. Round it down. If the number is between 4 and 5 (probability = 1 − 0.096 = 0.904) : rounded to 4.
    If it's between 5 and 6 (probability = 0.096) : rounded to 5.
    So, let's calculate the expected value : E = 4 × 0.904 + 5 × 0.096 = 4.096
I can't code it myself, but I roughely understand the code. I think it's here : mg_ore line 136.
Just realize how bored we would be if the world was perfect.

User avatar
Tomas Brod
Member
Posts: 34
Joined: Thu Sep 18, 2014 13:57
In-game: Brod
Location: Slovakia
Contact:

Re: Ores with high clust_scarcity

by Tomas Brod » Post

Gael de Sailly wrote:+1.

I may say exactely the same thing, maybe I've not understood exactely what you say.
  1. Calculate the average number of clusters in the chunk (for example if clust_scarcity = 50*50*50 = 125000, this number is 512000 / 125000 = 4.096)
  2. Add a random float number between 0 and 1. So, we have a number between 4.096 and 5.096
  3. Round it down. If the number is between 4 and 5 (probability = 1 − 0.096 = 0.904) : rounded to 4.
    If it's between 5 and 6 (probability = 0.096) : rounded to 5.
    So, let's calculate the expected value : E = 4 × 0.904 + 5 × 0.096 = 4.096
I can't code it myself, but I roughely understand the code. I think it's here : mg_ore line 136.
Exactly. I was about to write a patch, but I figured out that I need to read more about cpp.

I am going to implement this in lua. To see if it is working and to play.

User avatar
ArguablySane
Member
Posts: 116
Joined: Sun Oct 12, 2014 21:29

Re: Ores with high clust_scarcity

by ArguablySane » Post

Tomas Brod wrote:

Code: Select all

NumberOfClusters := Round( (ChunkVolume/ClustScarcity) + (Random(-100,100)/100) );
That might work, but it wouldn't be ideal. As scarcity increases the number of clusters should tend towards zero, but using your code it would tend towards a random number between -1 and 1. Negative numbers of clusters don't make sense, so in effect it would tend towards 0.5.

A better fix would be to use a poissonian distribution with mean equal to (volume/clust_scarcity):

Code: Select all

u32  nclusters = poisson_distribution(volume/clust_scarcity);
This would have the side effect of making a more random distribution of ores in general. For high-scarcity ores there would be a significant chance that any given chunk wouldn't contain any, but some chunks would also contain more than their fair share of ores.

Unfortunately, because minetest needs to use a bespoke pseudorandom number generator, I'd probably need to implement the poisson function myself. That would require becoming a lot more familiar with the code, so I'm not going to submit any pull requests immediately.
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests