Skip to content

Instantly share code, notes, and snippets.

@dsetzer
Last active December 4, 2020 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dsetzer/bbdb96f4bdf557e2e1d7faf5000d9243 to your computer and use it in GitHub Desktop.
Save dsetzer/bbdb96f4bdf557e2e1d7faf5000d9243 to your computer and use it in GitHub Desktop.
Probability tester for my bustadice simulator. It will decide at each roll whether to skip or to bet and the game stats are referring to all games both skips/bets while play stats are referring to only the games which were bet on. It's made to test the sim mode and won't place any actual bets unless you turn off sim mode where in that case it wi…
var config = {
simMode: { type: 'checkbox', label: 'Use Sim Mode', value: true },
skipRatio: { type: 'number', label: 'Skip Perc (%)', value: 75 },
payout: { type: 'multiplier', label: 'Target Payout', value: 2 },
};
Object.entries(config).forEach(c => window[c[0]] = eval(c[1].value));
let results = [], wins = 0, loses = 0, games = 0, hits = 0, misses = 0, plays = 0;
if (simMode === true) {
var simBalance = 1000000;
var sleep = ms => new Promise(r => setTimeout(r, ms));
this.balance = simBalance;
this.bet = (value, target) => {
if (this.balance !== simBalance) this.balance = simBalance;
return new Promise(async (resolve, reject) => {
if (value % 100 != 0) return reject("bet size must be evenly divisible by 100");
if (value < 100) return reject("bet size must be at least 100 (= 1 bit)");
if (target < 1.01 || target > 1e6) return reject("target multiplier must be between 1.01 and 1,000,000");
if (this.balance && this.balance < value) return reject("insufficient balance"); else if (!this.balance) this.balance = 0;
let id = (++this.fid || (this.fid = 0, 0)), timestamp = new Date().toDateString();
let multiplier = Math.round(Math.max(1, (0.99 / Math.random())) * 1e2) / 1e2;
if (multiplier < target) { this.balance -= value; } else { this.balance += value * (target - 1); }
simBalance = this.balance;
await sleep(100);
let result = { id: id, timestamp: timestamp, value: value, target: target, multiplier: multiplier, balance: this.balance, bankroll: Infinity };
return resolve(result);
}).catch((r) => { throw new Error(r); });
}
this.skip = () => {
return new Promise(async (resolve, reject) => {
let id = (++this.fid || (this.fid = 0, 0)), timestamp = new Date().toDateString();
let multiplier = Math.round(Math.max(1, (0.99 / Math.random())) * 1e2) / 1e2;
await sleep(100);
let result = { id: id, timestamp: timestamp, multiplier: multiplier, balance: this.balance, bankroll: Infinity };
return resolve(result)
});
}
}
Array.prototype.median = function () {
if (this.length >= 1) {
const median = this.slice().sort((a,b)=>a-b);
if ((median.length % 2) === 0) {
return (((median[median.length / 2] + median[(median.length / 2) - 1])) / 2);
}
return (median[Math.floor(median.length / 2)])
}
return -1;
}
for (;;) {
if (Math.random() < (skipRatio/100)) {
// do a skip
let result = await this.skip();
results.push(result.multiplier);
if (result.multiplier < payout) misses++;
else hits++;
} else {
// do a bet
let result = await this.bet(100, payout);
results.push(result.multiplier);
if (result.multiplier < result.target) {
loses++, misses++;
} else {
wins++, hits++;
}
plays++;
}
games++;
this.log(`---------------------------------------------`)
this.log(`Games: ${games}, Skips: ${games-plays}, Plays: ${plays} [${((plays / games)*100).toFixed(2)}%], Median: ${results.median()}`)
this.log(`Game Stats (Hits: ${hits} (${((hits / games) * 100).toFixed(2)}%), Misses: ${misses} (${((misses / games) * 100).toFixed(2)}%), Expected: ${(99 / payout).toFixed(2)}%/${(100 - (99 / payout)).toFixed(2)}%)`);
this.log(`Play Stats (Wins: ${wins} (${((wins / plays) * 100).toFixed(2)}%), Loses: ${loses} (${((loses / plays) * 100).toFixed(2)}%), Expected: ${(99 / payout).toFixed(2)}%/${((100 - (99 / payout))).toFixed(2)}%)`);
}
/* Copyright (c) 2020 Daniel Setzer. All rights reserved. */
@ivayloptrv
Copy link

Hey, I tried searching for a script that records my dice rolls history but I found one only for BAB. Do you have any for dice? Also BIG thanks for all the scripts you've created so far!

@dsetzer
Copy link
Author

dsetzer commented Oct 23, 2020

@Neonskull Yeah that's pretty easy to do, what exactly did you want it to save? and do what with it?

@wtfarabbit
Copy link

@dsetzer do you have discord or telegram so we can pay you for custom scripts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment