Changes

no edit summary
Line 56: Line 56:  
This means in order to get an ore, the chance for the previous ore must be less than 100%, so once iridium ore reaches 100%, no other metal ores can be made.
 
This means in order to get an ore, the chance for the previous ore must be less than 100%, so once iridium ore reaches 100%, no other metal ores can be made.
 
The probability to get each ore (from a random stone) is therefore:
 
The probability to get each ore (from a random stone) is therefore:
     iridium=chanceForOre*chanceForIridium
+
     iridium = chanceForOre*chanceForIridium
     gold=chanceForOre*(1-chanceForIridium)*chanceForGold
+
     gold = chanceForOre*(1-chanceForIridium)*chanceForGold
     iron=chanceForOre*(1-chanceForIridium)*(1-chanceForGold)*chanceForIron
+
     iron = chanceForOre*(1-chanceForIridium)*(1-chanceForGold)*chanceForIron
     copper=chanceForOre*(1-chanceForIridium)*(1-chanceForGold)*(1-chanceForIron)
+
     copper = chanceForOre*(1-chanceForIridium)*(1-chanceForGold)*(1-chanceForIron)
    
These probabilities are defined in the following code:
 
These probabilities are defined in the following code:
Line 81: Line 81:     
Additionally, up until this point, luck has not factored into the calculation.
 
Additionally, up until this point, luck has not factored into the calculation.
However, if it does not pass the ore chance check, it moves on to gemstone ores, dark grey rocks (stone ore), purple stones and mystic stones.
+
However, if it does not pass the ore chance check (this means the final chances for these will need <code>1-chanceForOre</code> included), it moves on to gemstone ores, dark grey rocks (stone ore), purple stones and mystic stones.
 
This is done in the following complex code (some unneeded sections related to coloured rocks have been removed, and additional comments added):
 
This is done in the following complex code (some unneeded sections related to coloured rocks have been removed, and additional comments added):
 
     double averageDailyLuck = Game1.player.team.AverageDailyLuck(Game1.currentLocation);
 
     double averageDailyLuck = Game1.player.team.AverageDailyLuck(Game1.currentLocation);
Line 122: Line 122:  
This can be understood as (where each check is if they pass the check for meeting the chance):
 
This can be understood as (where each check is if they pass the check for meeting the chance):
 
     if (!diamondCheck && gemCheck){
 
     if (!diamondCheck && gemCheck){
return gem
+
        return gem
 
     }
 
     }
 
     if (stoneCheck) {
 
     if (stoneCheck) {
Line 136: Line 136:  
         return diamond
 
         return diamond
 
     }
 
     }
     return stone
+
     return rock
 
However the use of diamondCheck twice means you cannot just use the chance for it twice, as it will either pass both times or fail both times, making calculations of chances more complex.
 
However the use of diamondCheck twice means you cannot just use the chance for it twice, as it will either pass both times or fail both times, making calculations of chances more complex.
 +
The simplest to understand is the gemstone ore.
 +
In order to return the gemstone ore, the diamond check must fail, and the gem check must pass. This is equivalent to:
 +
    (1-chanceForOre)*(1-chanceForDiamond)*chanceForGem.
 +
Additionally, this returns a random gem using the function <code>MineShaft::getRandomGemRichStoneForThisLevel</code><ref name="whichGem" />.
 +
This relies upon the code:
 +
    int whichGem = this.mineRandom.Next(59, 70);
 +
    whichGem += whichGem % 2;
 +
Which will randomly select an integer in the range [59,70), and then add 1 if it is odd.
 +
This has the effect of randomly selecting an even integer from 60 to 70 inclusive, with the integers from 60 to 68 inclusive having an equal likelihood and 70 being half as likely.
 +
This is because the mineRandom.Next(a,b) will return an integer greater than or equal to a and less than b, from internally generating a random number from 0 to 1, scaling it and offsetting it to be a random decimal number from 59 to 70, and then rounding down. This means that the range 59 to just below 61 will round to 59 or 60, which is then both forced to 60; while the numbers from 69 to 70 will round to 69 and then be converted to 70, meaning 70 has half the range. This means that the chance for jade (from 70) will be:
 +
    (1-chanceForOre)*(1-chanceForDiamond)*chanceForGem/11
 +
And the chance for the other gems (emerald, aquamarine, ruby, amethyst & topaz) will be:
 +
    (1-chanceForOre)*(1-chanceForDiamond)*chanceForGem*2/11
 +
The chance to not be a gem stone ore, and be some other option (other than diamond) relies upon either passing the diamond check, or failing the diamond check and failing the gemstone check. This chance is equal to:
 +
    chanceForDiamond+(1-chanceForDiamond)*(1-chanceForGem) = 1-(1-chanceForDiamond)*chanceForGem
 +
Then going through each return statement we have the final chances being:
 +
    stone = (1-chanceForOre)*(1-(1-chanceForDiamond)*chanceForGem)*chanceForStone
 +
    mystic = (1-chanceForOre)*(1-(1-chanceForDiamond)*chanceForGem)*(1-chanceForStone)*chanceForMystic
 +
    purple = (1-chanceForOre)*(1-(1-chanceForDiamond)*chanceForGem)*(1-chanceForStone)*(chanceForMystic)*chanceForPurple
 +
The next one to consider is is Diamond. As passing the diamond check skips the gem stone ore check, so it cannot be included in the chance. To be a diamond, it must pass the diamond check, which skips the gem check, and it must fail every other check. This gives:
 +
    diamond = (1-chanceForOre)*(chanceForDiamond)*(1-chanceForPurple)*(1-chanceForMystic)*(1-chanceForStone)
 +
And finally, the only other option is a normal rock. This could be calculated as whatever is left over, but for completeness, it must fail every check.
 +
    rock = (1-chanceForOre)*(1-chanceForDiamond)*(1-chanceForGem)*(1-chanceForPurple)*(1-chanceForMystic)*(1-chanceForStone)
      Line 148: Line 171:  
<ref name="whichOre">See <samp>FarmerTeam::getAppropriateOre</samp> in the game code.</ref>
 
<ref name="whichOre">See <samp>FarmerTeam::getAppropriateOre</samp> in the game code.</ref>
 
<ref name="chooseStoneType">See <samp>MineShaft::chooseStoneType</samp> in the game code.</ref>
 
<ref name="chooseStoneType">See <samp>MineShaft::chooseStoneType</samp> in the game code.</ref>
 +
<ref name="whichGem">See <samp>MineShaft::getRandomGemRichStoneForThisLevel</samp> in the game code.</ref>
 
</references>
 
</references>
84

edits