Skip to content

Instantly share code, notes, and snippets.

@dsetzer
dsetzer / climb3-v1.5-sim-dice.js
Last active January 15, 2023 14:07
climb3-v1.5 script for dice with included sim mode.
var config = {
baseBet: { label: 'Base Bet', type: 'balance', value: 1000 },
minPayout: { label: 'Target Min', type: 'multiplier', value: 1.08 },
maxPayout: { label: 'Target Max', type: 'multiplier', value: 50.00 },
divPayout: { label: 'Target Div', type: 'multiplier', value: 0.80 },
compRate: { label: 'Compound %', type: 'multiplier', value: 0.02 },
compStep: { label: 'Compound At', type: 'multiplier', value: 1.10 },
betSpeed: { label: 'Bet Speed', type: 'multiplier', value: 100 },
simMode: { label: 'Sim Mode', type: 'checkbox', value: true },
simBal: { label: 'Sim Balance', type: 'balance', value: 1000000 }
@dsetzer
dsetzer / cartesian-combos.js
Created July 31, 2020 19:39
Generate all possible parameter combinations using cartesian product.
function cartesian(...args) {
let r = [], max = args.length - 1;
let step = (arr, i) => {
for (let j = 0, l = args[i].length; j < l; j++) {
let a = arr.slice(0);
a.push(args[i][j]);
if (i === max) r.push(a); else step(a, i + 1);
}
}
step([], 0);
@dsetzer
dsetzer / bab-results-script.js
Created July 15, 2020 18:00
Generates previous games from within the script.
var config = {
span: { label: 'Previous Games', type: 'number', value: '100' },
outh: { label: 'Print Hashes', type: 'checkbox', value: false }
};
Object.entries(config).forEach((c) => window[c[0]] = c[1].value);
let hashes = new Map(), lastGame = engine.history.first();
let currentId = lastGame.id, currentHash = lastGame.hash;
for(let i = currentId, result, len = currentId - span; i >= len; i--){
hashes.set(i, String(currentHash));
currentHash = SHA256((currentHash));
@dsetzer
dsetzer / decimalExpansion.js
Created July 13, 2020 17:24
decimal expansion function
// borrowed from jQuery 1.7.2
var isNumeric = function(val){
return !isNaN(parseFloat(val)) && isFinite(val);
};
/**
* @author Larry Battle <http://bateru.com/news/contact-me>
* @date May 16, 2012
* @license MIT and GPLv3
*/
//decimalExpansion returns a string representation of a divided by b to a fixed length.
@dsetzer
dsetzer / bustadice-sim-mode.js
Last active October 30, 2020 20:41
Sim mode for bustadice based on my previous diceBetSimulate gist but easier to drop into a script and instructions.
/************* INSTRUCTIONS *************
Place it into a script right below the config section at the top and it will replace
the bet/skip function with mock functions which don't interact with the server.
A few points to note:
1. Latency won't exist with these, and results are returned almost instantly, this
could cause the browser to freeze up or make the script unobservable unless the
script includes a sleep or bet delay function. For convenience there's one included
but disabled by default, just enable the SIM_MODE_SLEEP setting.
#! /usr/bin/env python3
## NAME: duration.py
## USAGE: From shell prompt: python3 duration.py
## or within interactive python3 environment, import filename
## REQUIRED ARGUMENTS: none
## OPTIONS: none
## DESCRIPTION: Experiment to measure duration
## of random walk of n steps done k times each,
## starting from each value from ruin to victory,
## continuing until reaching either ruin or victory
@dsetzer
dsetzer / diceBetSimulate.js
Last active May 10, 2020 13:28
Replaces the bet function with one that provides authentic results at no cost.
this.bet = (value, target, balance) => {
return new Promise((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 (balance && balance < value) return reject("insufficient balance"); else if(!balance) balance = 0;
let id = (++this.fid || (this.fid = 0, 0)), timestamp = new Date().toDateString();
let multiplier = Math.round(Math.min(Math.max(1, (0.99 / Math.random())), 1e6) * 1e2) / 1e2;
if(multiplier < target) { balance -= value; } else { balance += value * (target - 1); }
return resolve({id, timestamp, value, target, multiplier, balance, bankroll: Infinity});
@dsetzer
dsetzer / ProbRunMulti.js
Last active June 10, 2020 05:21
Iterative run streak probability. [Possibly incorrect, if any math genius sees a flaw please let me know!]
// Probability of 1,2,3,...s or more streaks of r or more consecutive heads in n tosses
// of a coin having probability p of heads. Returns s values.
//
// P(j, i) = P(j, i - 1) + [P(j-1, i-r-1) - P(j, i-r-1)] * (1-p)p^r, for i > j*(r+1) - 1
//
// P(j, i) = p^(jr) * (1-p)^(j-1), for i = j*(r+1) - 1
//
// P(j, i) = 0, for i < j*(r+1) - 1
//
// P(0, i-r-1) = 1
@dsetzer
dsetzer / ProbRun.js
Last active November 8, 2021 18:26
Iterative run probability
// Probability of a r or more consecutive heads in n tosses
// of a coin having probability p of heads
// P(i) = P(i-1) + [1 - P(i-r-1)] * (1-p)p^r, for i > r
// P(r) = p^r
// P(i) = 0, for i < r
// where i is the flip.
// P is implemented as a circular array prob of size 0:r.
function ProbRun(n, r, p) {
let prob = [r], iter, last, i, j;
let c = (1 - p) * Math.pow(p, r);
/**
* BustabitAudio class
*/
(function () {
window.BustabitAudio = function () {
this.audio = {
won: new Audio("https://www.soundjay.com/misc/small-bell-ring-01a.mp3"),
lost: new Audio("http://www.freesfx.co.uk/rx2/mp3s/5/16873_1461333020.mp3")
};
this.audio.won.volume = 0.5;