Infinite resource with probability

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2127
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Infinite resource with probability

Post by Ranakastrasz »

I've been trying to modify the "Deep Ores Mod" by Darloth. I wanted to increase the ratio of stone you get per copper or iron. However, alterations had really bizzare effects.




https://forums.factorio.com/forum/vie ... 97&t=14694
The original.

Code: Select all

{type="item", name="iron-ore", amount=1, probability = 0.35},
{type="item", name="stone", amount=1, probability = 0.25},
{type="item", name="iron-ore", amount=2, probability = 0.40}
First modification. Results in no stone until depleted. Didnt check ratio after that.

Code: Select all

{type="item", name="iron-ore", amount=1, probability = 0.35},
{type="item", name="stone", amount=1, probability = 0.50},
{type="item", name="iron-ore", amount=2, probability = 0.40}
Second attempt. Results in 6 iron per 1 stone, instead of the expected 4:1 ratio.

Code: Select all

{name="iron-ore", amount_min = 1, amount_max = 3, probability = 1.0},
{name="stone", amount_min=1,amount_max = 1, probability = 0.50}
I can only assume that there is a bug here, or I don't understand how this stuff works. Probably both.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Infinite resource with probability

Post by Adil »

The original probabilities sum up to 1.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2127
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Infinite resource with probability

Post by Ranakastrasz »

I am aware of that. However, according to my research, that shouldn't matter, as they are supposed to all be independent random numbers.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

cartmen180
Filter Inserter
Filter Inserter
Posts: 358
Joined: Fri Jul 25, 2014 2:53 pm
Contact:

Re: Infinite resource with probability

Post by cartmen180 »

I played around with probabilities for mining ores some time ago. As I recall, the numbers worked out in the long term across multiple miners.
I am not sure about this but I believe i had the probabilities sum up to 1.
Check out my mods

UberWaffe
Fast Inserter
Fast Inserter
Posts: 202
Joined: Mon May 04, 2015 4:53 am
Contact:

Re: Infinite resource with probability

Post by UberWaffe »

@bobingabout had a similar issue at some point with his gems ore (that produces multiple outputs with probabilities).

He fixed it by giving his miner more storage slots.

Code: Select all

storage_slots = 6,
Note: Miner storage slots are not visible in game, but do exist.
The reason being, that miners only have 1 storage slot by default, meaning that when the random numbers do generate more than 1 output in a single tick, there is no storage slots for the others to be put into, hence the engine doesn't create them.

The miner will output the storage slots over multiple ticks.

I believe this is the same issue here. Maybe?

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2127
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Infinite resource with probability

Post by Ranakastrasz »

o_o
Well, that is almost certainly the problem. If I do the math.....

Well, It doesnt add up at all, since the infinite resource part almost certainly screws up the rest. Certainly explains why I got 100% iron until near depleted in the second case.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Infinite resource with probability

Post by bobingabout »

Infinite rersources do tend to mess things up a bit, it works differently for an item result than it does for a fluid result.

Fluids cannot exist freely in the world, so a fluid miner will give a result in a fluid box. they can also exist as fractions, so a fluid miner will give a certain number of fluid per mining cycle. This means that it is quite easy to change how much is produced, so infinite will scale the amount you get based on the amount in the resource.

Mining items are not stored in the machine, but deposited directly into the world. Items in the world can only exist as a stack of one, therefore what you get from mining items becomes a probabillity.

The probabillity of a resource being given is the item probabillity, multiplied by the "mining probabillity", calculated as min(current,normal)/normal (min is a function that returns the lowest value of the 2). so if you have a structure like the oil where normal is 10 times the minimum, then when you start to fall below the normal level as you aproach minimum, your cycles start skipping ores as the probabillity drops.

this basically means that with infinite ores, if you have the normal level or more, you mine as normal, but if you have less than the normal value, you get mining cycles where no ores are returned. so if your minimum is 10% of the normal value, and your item mining probabillity is 10%, then the chance of getting that item per mining cycle is reduced to 1%.

The easy fix for this problem is to set ore infinite values so that they never enter this depleated phase, by setting the normal to the same value as minimum, then the results never change as the ore is depleated to the minimum point. To set it in such a way that you'll never find a field that has less than the minimum, you'll need to set both values to 1.

There are other issues however... for exmaple, the display of the mining drill on infinite ore will display ore/sec, this is not in any way a true representation of what you get for 2 reasons. The first being that it will always give you a number assuming it is giving fluids, so if you have higher than the normal probabillity, it will over-estimate. the second reason is that it will add all ore patchs in the miner's field, where the miner actually mines them one at a time in a random sequence.
Last edited by bobingabout on Tue Oct 20, 2015 9:12 am, edited 1 time in total.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

SirRichie
Fast Inserter
Fast Inserter
Posts: 244
Joined: Wed Feb 25, 2015 4:50 pm
Contact:

Re: Infinite resource with probability

Post by SirRichie »

To add to the very nice analysis of bobingabout:

There is also a difference between a miner that has a single ore patch with probability 50% and a miner that has two ore patches with probability 25% (though I have not thoroughly tested this):
It seems that for each mining cycle, Factorio selects a single, non-empty ore patch in the miner's radius. It then evaluates the probability of that ore patch.

This also means that a miner with a single 100% ore patch, will work faster than a miner with a 100% ore patch and 5 10% patches.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Infinite resource with probability

Post by bobingabout »

SirRichie wrote:To add to the very nice analysis of bobingabout:

There is also a difference between a miner that has a single ore patch with probability 50% and a miner that has two ore patches with probability 25% (though I have not thoroughly tested this):
It seems that for each mining cycle, Factorio selects a single, non-empty ore patch in the miner's radius. It then evaluates the probability of that ore patch.

This also means that a miner with a single 100% ore patch, will work faster than a miner with a 100% ore patch and 5 10% patches.
From my observations, I will agree with this analysis. This is how I think it works.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Post Reply

Return to “Modding help”