Skip to content

Instantly share code, notes, and snippets.

@dsetzer
Created July 15, 2021 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsetzer/f4d21936a1a3699677123a4e162bb823 to your computer and use it in GitHub Desktop.
Save dsetzer/f4d21936a1a3699677123a4e162bb823 to your computer and use it in GitHub Desktop.
default martingale script from bustabit converted to bustadice with added sim mode.
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' },
}
},
win: {
value: 'base', type: 'radio', label: 'On Win',
options: {
base: { type: 'noop', label: 'Return to base bet' },
increase: { value: 2, type: 'multiplier', label: 'Increase bet by' },
}
},
simNop: { type: 'noop', label: 'Sim Mode' },
simMode: { type: 'checkbox', label: 'Use Sim Mode', value: true },
simBal: { type: 'balance', label: 'Sim Balance', value: 1000000 }
};
let currentLost = 0;
let currentLosses = 0;
let startBal = config.simMode.value ? config.simBal.value : this.balance;
let logEntry = "";
let currentGame = 0;
const sleep = ms => new Promise(r => setTimeout(r, ms));
const olog = this.log;
this.log = msg => {
olog(`#${currentGame} [${new Date(Date.now()).toLocaleString("en-US")}] ${msg}`);
};
let currentBet = config.baseBet.value;
this.log(`Script is running${config.simMode.value ? " in SIM-MODE with " + (config.simBal.value/100) + " bits initial balance." : ".."}`);
if (config.simMode.value) {
var simBalance = config.simBal.value;
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()) * 100) / 100;
if (multiplier < target) {
this.balance -= value;
} else {
this.balance += value * (target - 1);
}
simBalance = this.balance;
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()) * 100) / 100;
let result = {id: id, timestamp: timestamp, multiplier: multiplier, balance: this.balance, bankroll: Infinity};
return resolve(result);
});
};
}
for (;;) {
const result = await this.bet(Math.round(currentBet / 100) * 100, config.payout.value);
logEntry = `Bet ${Math.round(currentBet / 100)} bits @ ${config.payout.value}x.. Rolled @ ${result.multiplier}x. `;
if (result.multiplier >= result.target) {
if (config.win.value === "base") {
currentBet = config.baseBet.value;
} else {
console.assert(config.win.value === "increase");
currentBet *= config.win.options.increase.value;
}
logEntry += `Won ${Math.round(result.value * (result.target - 1) / 100)} bits! `;
} else {
logEntry += `Lost ${result.value / 100} bits!`;
if (config.loss.value === "base") {
currentBet = config.baseBet.value;
} else {
console.assert(config.loss.value === "increase");
currentBet *= config.loss.options.increase.value;
}
}
if (currentBet > config.stop.value) {
this.log(`Bet reached ${Math.round(currentBet / 100)} bits which triggered stop`);
break;
}
this.log(logEntry + `(Balance ${Math.round(this.balance) / 100}, Profit ${Math.round((this.balance - startBal) * 100) / 1e4})`);
await sleep(config.delay.value);
currentGame++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment