Last active
March 27, 2024 13:45
-
-
Save dsetzer/2e7bf0008b9578f19a4aab89011cce90 to your computer and use it in GitHub Desktop.
Bustabit script wrapper for use on bustadice. (proof of concept / demo! extremely minimal bustabit script API functionality)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var config = { | |
| baseBet: { type: 'balance', label: 'Base Bet', value: 100 }, | |
| payout: { type: 'multiplier', label: 'Payout', value: 2 } | |
| }; | |
| const dcheck = () => { try{ engine.getState() }catch(e){ return true } return false } | |
| const emitter = { | |
| on(name, func){this._s[name] = this._s[name] || []; this._s[name].push(func)},_s:{}, | |
| emit(name, ...args){if(!this._s[name]){return; } this._s[name].forEach(f=>f(...args))} | |
| } | |
| const dice = dcheck(); | |
| if(dice){ | |
| var engine = emitter; | |
| } | |
| //---------BEGIN BUSTABIT SCRIPT ---------- | |
| let baseBet = config.baseBet.value, currentBet = baseBet, payout = config.payout.value; | |
| engine.on('GAME_STARTING', () => { | |
| engine.bet(currentBet, payout); | |
| }); | |
| engine.on('GAME_ENDED', () => { | |
| let lastGame = engine.history.first(); | |
| if(!lastGame.wager) return; | |
| if(lastGame.cashedAt){ | |
| console.log(`We won! ${(lastGame.wager*lastGame.cashedAt-lastGame.wager)/100} bits`); | |
| currentBet = baseBet; | |
| }else{ | |
| console.log(`We lost ${lastGame.wager/100} bits`); | |
| currentBet *= (payout / (payout - 1)); | |
| } | |
| }); | |
| //----------END BUSTABIT SCRIPT ----------- | |
| if(dice){ | |
| function sleep(ms) {return new Promise(resolve => setTimeout(resolve, ms));} | |
| engine.bet = function(value, target){ this.wager = {v: value, t: target}; }; | |
| engine.history = {first(){ return this.lastGame; }}, engine.wager = null; | |
| for(;;){ | |
| engine.lastGame = null, engine.wager = null; | |
| await engine.emit('GAME_STARTING'); | |
| const result = engine.wager ? await this.bet(engine.wager.v, engine.wager.t) : await this.skip(); | |
| engine.history.lastGame = { bust: result.multiplier, wager: result.value || 0, | |
| cashedAt: (result.target && result.target <= result.multiplier ? result.target : 0) | |
| } | |
| await engine.emit('GAME_ENDED'); | |
| await sleep(100); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment