ruzli
8/14/2018 - 12:06 PM

New One

const baseBet = 2     // how many bits to bet initially
const target = 2.00     // target multiplier
const betMultiplier = 2 // what to multiply the bet size by when we lose a wager

let prevBet = 0
let _baseBet = baseBet
engine.log(`Starting new one.`)

while (true) {
  const { multiplier } = await engine.bet(_baseBet * 100, target)
  collectSound()
  prevBet = _baseBet
  if (multiplier < target) {   /*  Loss  */
    _baseBet = _baseBet + prevBet
    if (_baseBet > prevBet * 2){
        _baseBet = prevBet - 1
    }
    engine .log(`Lost bet. Multiplying bet size by ${betMultiplier} for new bet size of ${betSize(lossCount)} satoshis.`)
    await generateSeed()
  } else {  /*  Win  */
    gong()
    _baseBet = _baseBet - prevBet
    if (_baseBet < baseBet){
        _baseBet = baseBet
    }
    engine .log(`Won bet. Setting bet size to ${baseBet} satoshis.`)
  }
}

function betSize(lossCount) {
    let bet
    if (lossCount < 4){
        bet = baseBet
    }
    if (lossCount == 4){
        bet = 9
    }
    if (lossCount == 5){
        bet = 27
    }
    if (lossCount == 6){
        bet = 81
    }
    if (lossCount == 7){
        bet = 243
    }
    if (lossCount == 8){
        bet = 270
    }
    if (lossCount == 9){
        bet = 729
    }
    if (lossCount == 10){
        bet = 1913
    }
    if (lossCount == 11){
        bet = 4800
    }
  return bet * 100
}

async function generateSeed(){
    const { server_seed_hash } = await engine.newSeedPair()
    engine.log(`Server seed: ${server_seed_hash}`)
    try {
        const clientSeed = randomSeed()
        await engine.setClientSeed(clientSeed)
        engine.log(`Seed was set to: ${clientSeed}`)
    }
    catch(e){
        engine.log(`Client seed already was reset and not used`)
    }
}

function randomSeed(){
    const words = ['Ze3foA1gAlpha ','Zefo3AG3B2r2a3qtwvo ','Zefo3AG313Charlie ','ZefoA22G3Delta ','Zef3o1GEcho ','ZefoA22G5oxtrot ','ZefoAG34G223tewlf ','Ze1o5A3GHotel ','ZefoA3dda ','Ze5f3Auliet ','ZefoAGK3agalo ','ZefoAG24rqwima ',
    'Zef5oAG2Mrhe ','ZefoAG52ovember ','Ze67foGOscar ','Zefo3A45apayww ','Zef44A2Quebec ','ZefoAG433omeo ','ZefoA4GSierra ','ZefoA41GTngo ','ZefoA445GUniorm ','Ze37oGVictor ','ZefoA33W4hiskey ','ZefA3G4oXay ','Zef4Gpooper ','ZefoA3GZulu ']

    return words[Math.floor(words.length * Math.random())] + words[Math.floor(words.length * Math.random())] + words[Math.floor(words.length * Math.random())]}
function gong() {
    const audio = new Audio("https://bustadice.com/5bb187b7ef764e76fb519939f77288c1.mp3")
    audio.play()
    return new Promise(resolve => audio.onended = resolve)
    }
function collectSound(){
    // "http://kz-developer.ru/sounds/dieThrow1.wav"
    // "http://kz-developer.ru/sounds/dieThrow2.wav"
    // "http://kz-developer.ru/sounds/dieThrow3.wav"
    
    let pathStr = "http://kz-developer.ru/sounds/chipsHandle" + getRandomInt(6,7) + ".wav"
    
    const audio = new Audio (pathStr)
    audio.play()
    return new Promise(resolve => audio.onended = resolve)
}
function getRandomInt(min, max){
    return Math.floor(Math.random() * (max - min)) + min;
}
function toBits(satoshi){
  return satoshi / 100
}
function toSatoshi(bits){
  return bits * 100
}