Ores with high clust_scarcity

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

Ores with high clust_scarcity

by Tomas Brod » Wed Apr 22, 2015 20:48

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.
 

User avatar
Gael de Sailly
Member
 
Posts: 475
Joined: Sun Jan 26, 2014 17:01
GitHub: Gael-de-Sailly
IRC: Gael-de-Sailly
In-game: Gael-de-Sailly

Re: Ores with high clust_scarcity

by Gael de Sailly » Mon Apr 27, 2015 20:04

+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.
Very busy this year too, so do not expect me to be very active on the forum or in game. But I'm not about to drop Minetest forever :)
 

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

Re: Ores with high clust_scarcity

by Tomas Brod » Tue Apr 28, 2015 14:27

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 » Mon Jun 29, 2015 17:40

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.
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.
 


Return to Minetest Engine

Who is online

Users browsing this forum: No registered users and 2 guests

cron