Page 1 of 1

Ores with high clust_scarcity

PostPosted: Wed Apr 22, 2015 20:48
by Tomas Brod
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.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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.

Re: Ores with high clust_scarcity

PostPosted: Mon Apr 27, 2015 20:04
by Gael de Sailly
+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.

Re: Ores with high clust_scarcity

PostPosted: Tue Apr 28, 2015 14:27
by Tomas Brod
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.

Re: Ores with high clust_scarcity

PostPosted: Mon Jun 29, 2015 17:40
by ArguablySane
Tomas Brod wrote:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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):
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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.