Blackjack Simulator
By: Matthew Bailey
Tags: Gambling, Blackjack, Simulation, Python, Tutorial

Strategy Testing

Now that everything is ready to go, let’s test some different strategies. Although some strategies we test call for varying bets, we’ll start out with the same starting bet each time. And in the strategies that do vary our bets, over the long run we can expect our average bet of any single strategy to be pretty close to this starting bet, based on how the bets are being calculated (details below). This will help us compare expected ending chip values between strategies. To initialize each of our simulation runs, we’ll start with a stack of $10,000 chips and an initial bet of $100.

We’ll also set the random seed before we run each strategy so our results are consistent and reproducible.

Strategy 1: The Basic Bet

The first strategy could not be simpler — Just bet $100 every time. This will give us a good baseline indication about the overall expected return of playing Blackjack.

Strategy 1 Gives us a house edge of 0.27%, a pretty good result. This is a small edge for a casino game. Although we know we’d lose in the long run, we could play this strategy for a long time and maximize our enjoyment time playing the game. The smaller the house edge, the longer we’ll be able to play without losing our entire chip stack. As you can see, there is still a large amount of variability in any single outcome. So in one two hour session it’s 47.89% possible we walk away with a profit. But our replications here give us a pretty good idea of long run value and the true house edge of the game.

Strategy 2: Our Luck Must Turn

Strategy 2 will vary the bets we make. We’ll start at the baseline of $100. If we lose two hands in a row, we’ll increase our next bet by $10. If we win two hands in a row, we’ll subtract $10 from our next bet. This is a strategy actually suggested to me by a friend once. The logic being, if we hit a losing streak, we can eventually expect our luck to turn around and when it does, we’ll benefit from an increased bet size. Also, the opposite being that if we hit a big winning streak, let’s decrease our bet to lessen the impact of an inevitable loss that must be coming. It kind of makes sense in theory, although the inability for us to predict wins and losses before cards are dealt leads me to believe this is just creating inefficiencies. But let’s see how it plays out.

Immediately we see that Strategy 2 isn’t quite as good as Strategy 1, due to the higher house edge. Also, our output graph is interesting. Because of the much higher variability, we’re seeing some pretty extreme positive and negative values. As we run many replications, the chance of an extreme output high or low becomes a near certainty. And because we’re varying our bets this time, our variability is more than double that of Strategy 1. Let’s take some of these extreme observations off the ends and look at the graph again:

This gives us the normal distribution were used to seeing. We’ll still take our statistics from the original, but I wanted to confirm here that we’re still seeing the correct output distribution.

Note: We’re now seeing some negative ending chip stacks. This is fine for our purposes, in this case negatives will represent a player buying back in once they hit 0 chips. So -5000 would indicate the player lost the initial $10,000 + $5,000 more.

Strategy 3: Card Counting

Card counting is an intriguing strategy. If done correctly, the player can actually turn the odds of the game in their favor. And since casinos are in the business of making money, they tend to frown upon this type of strategy (to say the least). Today, the casinos take steps to insure this type of strategy is no longer profitable. However, let’s see if we can recreate this result with our simulation.

The basics of card counting are actually surprisingly simple. Low cards (2–6) are assigned +1, middle cards (7–9) are assigned 0, and high cards (10-A) are assigned -1. All the player has to do is keep a running count of these values, and adjust their bet depending on if the count is high or low. This is easier said then done of course, it requires great concentration from the player. But it’s actually quite simple from a math perspective. This idea is that a high count creates a player advantage: There are more high cards left in the deck, so the player will hit more Blackjack’s and the dealer will bust more often. Low counts are not favorable for the player, so in these cases the bet must be decreased. Some more details can be found here: https://en.wikipedia.org/wiki/Card_counting

There are nuances in various card counting systems, and likely different bet adjusting systems. But for this test, we’ll scale the bet based on what the count is. For example, for a count of +10 we’re going to bet 5x our original bet. For a count of -10, we’re going to decrease our bet by 5x.

We’ve brought down the house! This is a great result, we’ve actually managed to turn the advantage in favor of the player. In a real setting, a card counting player only plays when counts are really high (called into the table by a spotter), and gets out fast when the count starts to drop. Using this method as well as tweaking the logic and bet amounts would likely result in even greater profits for this strategy. However, the fact that we’re seeing a long run player advantage with this basic implementation here is an exciting result. I’m willing to bet none of our other strategies will be this profitable.

Strategy 4 — Hit Me

Strategy 4 represents an overzealous player. We’ll adjust some of the strategy dataframes so that the player chooses to Hit in more situations, even though the optimal stratgies dictate otherwise. This is a pretty realistic scenario, since any casual player is unlikely to know the optimal strategy decision in every situation. For even more experienced players, mix in some emotion, human error, and even a little booze at the table and it’s doubtful the correct decision will be made every single time. In this strategy, we’ll go back to a consistent $100 bet.

Yikes! A whopping 3.15% house advantage with this strategy. Intuitively, this makes sense. We’re deviating from the optimal strategy, so we’d expect it to perform worse. Also, because we’re erroring in the aggressive direction, it’s no wonder we see a steep drop. Hitting more often means the player will bust more often. And if a player busts, they lose the hand no matter what the dealer does. So here the player would be giving up potential wins when the dealer busts, had they correctly decided to Stand intead of Hit.

Strategy 5 — I’m Good, Thanks

Here we’ll take the opposite approach of Strategy 4. We’ll adjust the basic strategy dataframe to Stand more often, when the book says we should Hit. This will represent a more conservative player, who is weary of busting and is counting on the dealer to bust instead. Again, I’d expect a sub optimal result from this strategy- but how do you think it will compare to the aggressive Hit strategy?

Still not a great strategy, but the long run return is considerably better than the aggressive strategy with a 0.94% house edge. This makes sense since we’re allowing more opportunities for the dealer to bust, and the player themselves is also busting less. Clearly this also gives up some wins when optimal strategy dictates you should Hit, but overall this is much more viable than the aggressive Strategy 4.

Strategy 6 — Back to Basics

Our last tested strategy will go back to the optimal strategy actions in terms of Hit and Stand. However, for this run we’ll completely rule out the possibility of splitting or doubling down. This will simulate a player who knows basic strategy, but isn’t knowledgeable about some of the additional scenarios where these choices would be advantageous.

A surprisingly poor result. This goes to show how important Splitting and Doubling Down are to long term player returns. My gut would have thought one could get a house edge a little bit closer to Strategy 1 with this simple method, but it turns out this is actually the second to worse option. So if you want to enjoy your next Blackjack game a bit longer, be sure to study those Split and Double Down situations.