Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ruzli/b8edf68ef91c8c279c4a12a10101a94a to your computer and use it in GitHub Desktop.
Save ruzli/b8edf68ef91c8c279c4a12a10101a94a to your computer and use it in GitHub Desktop.
Simple Martingale with losing streak length stop loss
const baseBet = 100 // how many satoshis to bet initially
const target = 2.1 // target multiplier
const betMultiplier = 2 // what to multiply the bet size by when we lose a wager
const stopGameAfterLoss = 9 /* Trigger will lead to drop/stop script */
const sleepTimeInMS = 100
const dropInsteadOfStopScript = false /* stop script or drop losses and continue play */
const changeSeed = 0 /* How much losses obtain, and then change seed to decrease chance of big streak, 0 to disable */
const engine = this
let lossCount = 0
this.log(`Starting simple martingale with a base bet of ${baseBet} satoshis.`)
while (true) {
await sleep(sleepTimeInMS)
if (lossCount >= stopGameAfterLoss){
if (dropInsteadOfStopScript == true){
lossCount = 0
} else{
await this.stop()
}
}
if (lossCount > changeSeed && changeSeed != 0) {
await generateSeed()
}
// make the bet and wait for the result
const { multiplier } = await this.bet(betSize(lossCount), target)
if (multiplier < target) { // loss
collectSound()
lossCount++
this.log(`Lost bet. Multiplying bet size by ${betMultiplier} for new bet size of ${betSize(lossCount)} satoshis.`)
} else { // win
gong()
lossCount = 0
this.log(`Won bet. Setting bet size to ${baseBet} satoshis.`)
}
}
function betSize(lossCount) {
const bet = baseBet * Math.pow(betMultiplier, lossCount)
return Math.round(bet / 100) * 100
}
function gong() {
const audio = new Audio("https://bustadice.com/5bb187b7ef764e76fb519939f77288c1.mp3")
audio.play()
return new Promise(resolve => audio.onended = resolve)
}
function collectSound(){
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)
}
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 = ['Alegra ','Bravon ','Charlik ','Delago ','Zecho ','Forextromb ','Hotelka ','Gnomus ','Addicted ','Aurelia ','Zigalo ','Wiverma ',
'Mariner ','Octoberfest ','Nascar ','Papaja ','Alberts ','Gomus ','Fierra ','GTO ','Unicorn ','Vicantus ','Siski ','Xavier ','Poiuplet ','Antutulika ']
return words[Math.floor(words.length * Math.random())] + words[Math.floor(words.length * Math.random())] + words[Math.floor(words.length * Math.random())]
}
function getRandomInt(min, max){
return Math.floor(Math.random() * (max - min)) + min;
}
async function sleep(ms){return new Promise(resolve => setTimeout(resolve, ms))}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment