Skip to content

Instantly share code, notes, and snippets.

@dsetzer
Created August 1, 2019 06:56
Show Gist options
  • Save dsetzer/38b4ffcf0eb02b25e2376e424926f9a8 to your computer and use it in GitHub Desktop.
Save dsetzer/38b4ffcf0eb02b25e2376e424926f9a8 to your computer and use it in GitHub Desktop.
Complete rewrite of apexograph for bustabit
var config = {
baseBet: { type: 'balance', label: 'Added Base Bet', value: 10000 }, // Extra amount added to base bet.
betBalance: { type: 'multiplier', label: 'Max Bettable Bal', value: 0.05 },// Max portion of bal to bet with.
maxPayout: { type: 'multiplier', label: 'Payout Max Clamp', value: 3 }, // Upper bound limit on payout.
minPayout: { type: 'multiplier', label: 'Payout Min Clamp', value: 1.5 }, // Lower bound limit on payout.
debug: { type: 'checkbox', label: 'Verbose Log Output', value: false }, // Outputs additional information.
};
const debug = config.debug.value;
let hmrsv = 3, results = [], loses = [], vectorApex = 0, nextBet = 0;
engine.getState().history.forEach(h => results.push(h.bust));
function calcTarget(hmrsv, results) {
const pLen = results.length
if (pLen < hmrsv) {
if (debug) { log("[DEBUG] Not enough input to slice. Returning.. "); } return;
}
const r = results.slice(-hmrsv).sort((a, b) => a - b), len = r.length, mid = Math.floor(len / 2)
return clampTarget((len % 2 ? r[mid] : ((r[mid - 1] + r[mid]) / 2)));
}
function roundBit(bet) {
return Math.max(100, Math.round(bet / 100) * 100);
}
function calcBet() {
const betBalPerc = config.betBalance.value, lossCount = loses.length || 0;
const baseBet = 0 + config.baseBet.value + (userInfo.balance * (betBalPerc / (200 - lossCount)));
vectorApex = calcTarget(hmrsv, results);
if (!lossCount) {
if (debug) log(`[DEBUG] Base bet ${baseBet/100}, no losses.`);
return baseBet;
}
const losses = (loses.reduce((a, b) => a + b) * 100);
nextBet = roundBit((baseBet + losses) / (vectorApex - 1));
if (debug) log(`[DEBUG] Next ${nextBet/100}, (base ${baseBet/100}+(${losses/100}/${vectorApex} losses)`);
return nextBet;
}
engine.on('GAME_STARTING', () => {
if (results.length < hmrsv) return;
nextBet = roundBit(calcBet()), vectorApex = calcTarget(hmrsv, results)
engine.bet(nextBet, vectorApex);
log(`[INFO] Balance: ${userInfo.balance/100} bits. Betting ${nextBet/100} bits @ ${vectorApex}x next.`)
});
engine.on('GAME_ENDED', () => {
const lastGame = engine.history.first();
results.push(lastGame.bust);
if (results.length < hmrsv) {
if (debug) log(`[DEBUG] gathering initial data (${results.length}/${hmrsv} results)`);
return;
}
if (lastGame.wager){
if(lastGame.cashedAt) {
loses = []
const profit = lastGame.wager * lastGame.cashedAt - lastGame.wager;
log(`[INFO] (WON) Bust at ${lastGame.bust}x, Cashed at ${lastGame.cashedAt}x for ${profit/100} bits profit.`);
} else {
loses.push(nextBet / 100);
const loss = loses.reduce((a, b) => a + b);
log(`[INFO] (LOST) Bust at ${lastGame.bust}x, Current losses at ${loss} bits`)
}
}
});
function clampTarget(target) {
return Math.max(config.minPayout.value, Math.min(config.maxPayout.value, target));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment