Skip to content

Instantly share code, notes, and snippets.

@dsetzer
dsetzer / IterativeProb.js
Created Oct 25, 2021
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.
View IterativeProb.js
/**
* 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);
@dsetzer
dsetzer / Pattern-System-v1.2.js
Last active Oct 11, 2021
Dynamic Pattern System v1.2 work in progress prototype for bustabit/bustadice scripts.
View Pattern-System-v1.2.js
const tokenList = [
['R', (r) => { return (r.bust < 1.98); }], // Result is red (less than the median)
['G', (r) => { return (r.bust >= 1.98); }], // Result is green (equal/greater than median)
['W', (r) => { return (r.wager && r.cashedAt); }], // Bet was placed and won
['L', (r) => { return (r.wager && !r.cashedAt); }], // Bet was placed and lost
['S', (r) => { return (!r.wager); }], // Game was skipped (no bet placed)
['B', (r) => { return (r.wager); }] // Game was played (bet placed)
];
// ----------------------- V1.2 -------------------------
@dsetzer
dsetzer / downloadString.js
Last active Aug 31, 2021
Initiates a file download from javascript. No longer works from within sandboxed iframes.
View downloadString.js
function downloadString(data, fileName = 'download.txt', fileType = 'text/plain') {
var blob = new Blob([data], {type: fileType});
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, fileName);
} else{
var e = document.createEvent('MouseEvents'),
a = document.createElement('a');
a.download = fileName;
a.href = window.URL.createObjectURL(blob);
a.dataset.downloadurl = [fileType, a.download, a.href].join(':');
@dsetzer
dsetzer / default-martingale-sim.js
Created Jul 15, 2021
default martingale script from bustabit converted to bustadice with added sim mode.
View default-martingale-sim.js
var config = {
baseBet: { value: 100, type: 'balance', label: 'Base Bet' },
payout: { value: 2, type: 'multiplier', label: 'Target Payout' },
stop: { value: 1e8, type: 'balance', label: 'Stop if bet >' },
delay: { value: 100, type: 'number', label: 'Bet Speed' },
loss: {
value: 'increase', type: 'radio', label: 'On Loss',
options: {
base: { type: 'noop', label: 'Return to base bet' },
increase: { value: 2, type: 'multiplier', label: 'Increase bet by' },
@dsetzer
dsetzer / round-prec.js
Last active Apr 14, 2021
Rounding with precision
View round-prec.js
// Arrow functions
const round = (num, prec) => (prec = 10 ** prec, Math.round(num * prec) / prec);
const roundUp = (num, prec) => (prec = 10 ** prec, Math.ceil(num * prec) / prec);
const roundDown = (num, prec) => (prec = 10 ** prec, Math.floor(num * prec) / prec);
// Classic functions
function round(num, prec) {
prec = Math.pow(10, prec);
return Math.round(num * prec) / prec;
}
@dsetzer
dsetzer / bab_to_ether-dice.js
Created Mar 21, 2021
Script wrapper for running bustabit scripts on ether-dice. This expects the bustabit script to be standard format where bets are placed at GAME_STARTING event. Scripts with everything in GAME_ENDED will skip endlessly. Also don't expect any Ruzli scripts to work, it's a miracle those run to begin with.
View bab_to_ether-dice.js
engine.bet=function(e,n){this.nextBet={value:e,target:n}},engine.getState=(()=>{}),engine.cashOut=(()=>{});const gameResultFromHash=()=>{},SHA256=()=>{};engine.history={first(){let e=engine.nextResult;if(e||(e=engine.getLastGamePlayed),e){let n={id:e.id,hash:e.hash,bust:e.crash};return["NOT_PLAYED","SKIPPED"].includes(engine.getLastGamePlay)||(n.wager=e.wager,e.cashout<=e.crash&&(n.cashedAt=e.cashout)),n}return{id:0,hash:"none",bust:0,wager:0,cashedAt:0}}};const log=console.log,stop=engine.stop,userInfo={get uname(){},get balance(){return engine.getBalance}};engine.on("script_started",()=>{setTimeout(async()=>{for(;;)engine.nextBet=null,engine.nextResult=null,await engine.emit("GAME_STARTING"),null!==engine.nextBet?(engine.emit("BET_PLACED",{uname:"temp",wager:engine.nextBet.value,payout:engine.nextBet.target}),engine.nextResult=await engine.placeBet(engine.nextBet.value,engine.nextBet.target)):engine.nextResult=await engine.skip(),engine.emit("GAME_STARTED"),"WON"===engine.getLastGamePlay&&engine.emit("CASHE
@dsetzer
dsetzer / results-verifier.js
Created Feb 9, 2021
Result verifier adapted for use inside of a bustadice script.
View results-verifier.js
var config = {};
(function (I) {
function w(c, a, d) {
var l = 0, b = [], g = 0, f, n, k, e, h, q, y, p, m = !1, t = [], r = [], u, z = !1; d = d || {}; f = d.encoding || "UTF8"; u = d.numRounds || 1; if (u !== parseInt(u, 10) || 1 > u) throw Error("numRounds must a integer >= 1"); if (0 === c.lastIndexOf("SHA-", 0)) if (q = function (b, a) { return A(b, a, c) }, y = function (b, a, l, f) {
var g, e; if ("SHA-224" === c || "SHA-256" === c) g = (a + 65 >>> 9 << 4) + 15, e = 16; else throw Error("Unexpected error in SHA-2 implementation"); for (; b.length <= g;)b.push(0); b[ a >>> 5 ] |= 128 << 24 - a % 32; a = a + l; b[ g ] = a & 4294967295;
b[ g - 1 ] = a / 4294967296 | 0; l = b.length; for (a = 0; a < l; a += e)f = A(b.slice(a, a + e), f, c); if ("SHA-224" === c) b = [ f[ 0 ], f[ 1 ], f[ 2 ], f[ 3 ], f[ 4 ], f[ 5 ], f[ 6 ] ]; else if ("SHA-256" === c) b = f; else throw Error("Unexpected error in SHA-2 implementation"); return b
}, p = function (b) { return b.slice
@dsetzer
dsetzer / default-bab-mart-bustadice.js
Last active Feb 12, 2021
Bustadice's default martingale script is less configurable than bustabit's so I made a bustadice version out of it. (this is for use on bustadice).
View default-bab-mart-bustadice.js
var config = {
baseBet: { value: 100, type: 'balance', label: 'base bet' },
stopBet: { value: 1e8, type: 'balance', label: 'stop if bet >' },
basePayout: { value: 2, type: 'multiplier' },
stopPayout: {value: 20,type: 'multiplier',label: 'stop if payout >'},
lossBet: {
value: 'increase', type: 'radio', label: 'Bet On Loss',
options: {
base: { type: 'noop', label: 'Return to base bet' },
increase: { value: 2, type: 'multiplier', label: 'Multiply bet by' },
@dsetzer
dsetzer / LD2WD4.js
Last active Dec 7, 2021
Simple script I made for bustadice. It bets on 2x, doubles the bet amount on a loss and divides the bet by 4 if it's greater than 8 times the base bet otherwise by 2. It's not a set&forget script, it's risky but more profitable than plain martingale and it's manageable at a slow bet speed.
View LD2WD4.js
var config = {
baseBet: { type: 'balance', label: 'Base Bet', value: 128},
betSpeed: { type: 'number', label: 'Bet Speed', value: 800}
}
Object.entries(config).forEach(c => window[c[0]] = c[1].value);
var s = t => new Promise(r => setTimeout(r, t));
for(let b = baseBet; ;b=Math.max(baseBet, b)){
await this.bet(Math.round(b / 100) * 100, 2).then(r => {
b = r.multiplier >= r.target ? b / (b > baseBet * 8 ? 4 : 2) : b * 2;
}).then(() => s(betSpeed));