Monthly Archives: January 2015

Brute forcing the roulette wheel

There comes a time in every programmer’s life where they want to write a simulation to see how much they’d lose at the tables. Here’s mine. It’s a test of the Martingale Betting Strategy using a simulated roulette wheel.

The Martingale Betting Strategy is based on the idea that with payouts of 1 to 1, there is a good chance that you can recover lost bets when you achieve a win. The strategy has been used in roulette, where the probability of winning on red and black is close to 50%.

In general, the strategy is to double a bet whenever you lose in the hopes that the color you lost on will eventually come back around and you’ll recover your loss. For example, if you bet $1 on black and lose, you would then place $2 on black the next time. If black wins on the next spin, you recover your lost $1 and gain $1. If black loses again, you double the $2 and make a $4 bet. If you win this time, you’ve recovered the $1 + $2 you’ve spent and collect a $1 gain. If you lose again, you double the bet to $8. And so on. Again, the idea being that black will eventually come around and, so long as you keep doubling the bet, you’ll eventually recover your losses while earning a $1 gain whenever you don’t lose. There are 38 slots on an American roulette wheel: 18 black, 18 red, and 2 green. The probability of hitting a black or red on any single spin is 47.37%.

The bane of this system is the inevitable streaks of a particular color. Doubled bets increase exponentially. A $1 bet doubled 10 times becomes a whopping $1024 ($2, $4, $8, $16, $32, $64, $128, $256, $512, $1024)! In theory, if you have an infinite bank roll, you would always recover your losses because black always does come back round eventually. In practice, the upper limit is the table’s max bet and the money you bring to the table. You may not have a chance to recover your losses before exceeding the table limit on doubled bets.

Probability tells us that eventually we’ll either lose our bank roll or hit the table max bet. This simulation was written to visually represent how long one might go before hitting that wall.

For this simulation we will run up to 100,000 spins on a roulette wheel with bets using a modified version of the classic Martingale Strategy.

This simulation assumes the conditions of the standard video roulette machines I played in Vegas casinos. $3 minimum bet. $1000 maximum bet. I’m going to give it a bank roll of $1000 just to be generous. The max number of spins will be 100,000 (provided we don’t bust or exceed the table limits before reaching it). To achieve the minimum bet, we’ll start with $1 on red and $2 on black and double the bet on a losing color, while placing $1 on the winning color. Betting $1 on the opposing color is the only deviation from the classic Martingale Strategy, which only calls for doubling losing bets. However, this is both necessary to achieve the minimum bet of $3 total and also what you ought to do anyway. You have a 47.37% chance of recovering your loss by winning a doubled bet. However, in the absense of that, you will necessarily gain $1 unless it lands on green (a 5.26% chance). I maintain this is an improvement on the classic Martingale.

Spoiler alert, the house usually wins.

Spin the wheel here:

http://jeremyparnell.com/simulations/martingale.aspx