Skip to content

Instantly share code, notes, and snippets.

@domdomegg
Created July 8, 2020 15:49
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 domdomegg/96716b0f236bb6e416ef1c7b393e42e5 to your computer and use it in GitHub Desktop.
Save domdomegg/96716b0f236bb6e416ef1c7b393e42e5 to your computer and use it in GitHub Desktop.
Martingale casino wheel betting strategy simulator
// Simple (probably buggy) simualtor for the Martingale betting strategy on a casino wheel
// Slightly dodgy coding, bashed out quickly in 10 mins to prove a flatmate wrong...
const randomWin = () => {
return Math.random() < 0.49;
}
let stats = {
counter: 0,
wins: 0,
losses: 0,
totalNetWorthChange: 0,
gamesPlayed: 0
};
let startingBet = 0;
let startingAmount = 700;
let stopAmount = startingAmount + 1000;
let currentBet = startingBet;
let netWorth = startingAmount;
for (let i = 0; i < 1e6; i++) {
while(true) {
if (netWorth > stopAmount) {
stats.wins++;
break;
}
if (netWorth - currentBet < 0) {
stats.losses++;
break;
}
netWorth -= currentBet;
if(randomWin()) {
netWorth += currentBet*2;
currentBet = 2;
} else {
currentBet *= 2;
}
if (netWorth < startingAmount) {
stats.losses++;
break;
}
stats.counter++;
}
stats.totalNetWorthChange += netWorth - startingAmount;
stats.gamesPlayed++;
// console.log(`Current stats after ${stats.counter} games:`);
// console.log(`Net worth: £${netWorth}`);
// console.log(`Change in net worth: £${netWorth - startingAmount}`);
// console.log(``);
stats.counter = 0;
netWorth = startingAmount;
currentBet = startingBet;
}
console.log(``);
console.log(`###########################################`);
console.log(`Total stats`);
console.log(`Wins: ${stats.wins}`);
console.log(`Losses: ${stats.losses}`);
console.log(`Sum change in net worth: £${stats.totalNetWorthChange}`);
console.log(`Average change in net worth: £${(stats.totalNetWorthChange/stats.gamesPlayed).toFixed(2)}`);
console.log(``);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment