Created
October 25, 2021 13:17
-
-
Save dsetzer/92796ac864acd55b61e3b9dd0cf3959b to your computer and use it in GitHub Desktop.
Finds the cumulative win probability of a target payout in bustabit/bustadice. Results parameter expects an ordered array of numbers representing the games bust history.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Calculates current cumulative geometric probability | |
* @param payout Target payout to calculate for | |
* @param results Array of ordered results | |
* @param precision Num decimal places accuracy | |
* @param debug Output result slice to console | |
* @returns Cumulative geometric win probability | |
*/ | |
function getCumulativeProb(payout, results, precision, debug = false) { | |
let prc = 10 ** Math.max(1, Math.min((precision || 18), 18), 1); | |
if (Array.isArray(results) && results.length) { | |
for (let i = 0, j = results.length; i < j; i++) { | |
if (results[j - i] >= payout) { | |
let pmf = (1 - ((1 - (0.99 / payout)) ** i)); | |
let res = Math.min(1, Math.max(Math.round(pmf * prc) / prc, 0)); | |
(debug && console.debug(`${payout}x : ${res*100}% [${results.slice(-i)}](${i})`)); | |
return res; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment