The Perfect Count for Beating the House in Blackjack by Riley Howsden Medium

Under normal circumstances, the house has the advantage when it comes to the game of Blackjack. Of course, that is until you factor in card counting, which a player can use to drive long-term gains… Riley Howsden

·Follow

12 min read·Jun 24, 2021

--

Listen

Share

Before we take on the simulation task of determining this counting system, it is worthwhile to go over some standard counting systems. For each of these systems, there are three fundamental properties, which mostly revolve around human ease of use:

  • Integer-centric — most systems only assign integer values to cards; a few assign half-integer values to cards
  • Level — simple methods only include unique values from -1 to +1 and are considered level one, but more extensive ranges do exist, such as -3 to +3, which is a level three counting system
  • Balance — each system is either balanced, the total count of the deck sums to zero, or unbalanced

Perhaps the most popular balanced card counting system ever used is “Hi-Lo.” The value of each card is as shown:

In this setup, all high cards, 10 through A, are valuable to the player; when these cards surface, we take a step in the negative direction. On the other hand, all low cards, 2 through 6, are valuable to the dealer, and therefore, we take a step in the positive direction when they exit play. If the overall count is high, the player’s chance of winning is more likely. In these situations, the player should bet more on upcoming hands while keeping to the minimum bet when the count is negative as the odds are against them. It is essential to call out that most people are unaware that an intelligent betting scheme is the main tactic in card counting; most believe that players gain an advantage solely by altering play strategy based on the count. Fortunately, this works in the counter’s favor as remembering the correct play strategy under normal conditions is quite daunting in itself; memorizing when to deviate from that play adds another layer of complexity.

Since our sole focus will be on betting efficiency, we will stick to the core Blackjack strategy. However, other players will likely focus on other aspects in choosing their favorite counting system. Therefore a wide range has been created over time; here are some examples of other card counting systems.

The “Perfect” Count

Looking over the previous table of systems, you may wonder how one might arrive upon a sound counting system. Is it a process of trial and error, or is there a computational approach that could determine reasonable card values? Note that one of the characteristics mentioned in the last section, integer-centric, is mostly present in the systems above. What would happen if we were to relax that constraint and allow all real numbers? What if the range of values were unbounded? Of course, by removing these limitations, the system will likely not be usable by humans, but this will allow us to seek each card’s ideal weights, or in other words, the perfect count.

Previous Attempts

In the past, I’ve approached this problem by initializing simulations with one of the already known counting systems above and creating slight perturbations in their values. Then, after simulating enough hands, I could assess the new counting system against the old, and if the new system had better properties, it would take over as the “best” count. This random search would continue until gains diminished, in which the current count would be declared the winner. However, since this approach was primarily brute force, it was highly inefficient; each count scenario needed to see tens of millions of hands to ensure statistical significance compared to the other count. Also, I had to accept that simulating thousands of possible counting systems had created a multiple testing problem. Therefore, it was possible to adopt a counting system that was not better than the previous one.

Simplifying the Solution

Upon reexamining this problem, I realized an entirely different approach that might shed valid results. Instead of enforcing a specific system for a simulation and calculating its ROI, what if I just simulated the hands of Blackjack while logging the card history? After each hand, I could also tack on the amount gained or lost; the output would look something like this:

A random sample of pre-hand card counts and outcome of the upcoming hand The counts for each value should be intuitive, effectively mapping the number of times we had seen that card before the current hand began. The range of these values is a function of the number of decks in the Blackjack shoe, which is commonly six. Therefore, the number of times we have seen a card will range from 0 to 24 in our simulations. Outcomes will most often take on the following values:

  • 0 — Draw
  • 1 — Player Won
  • 1.5 — Player Blackjack
  • 2 — Double Down & Player Won
  • -1 — Dealer Won / Dealer Blackjack
  • -2 — Double Down & Dealer Won

Technically, however, the integers can exceed two when hands split, and multiple double downs occur, so while infrequent, it shouldn’t cause alarm to see numbers at or greater than three here.

Looking at this data set, you may have arrived at the same lightbulb moment that I stumbled upon recently. Can we just fit a basic linear regression onto this dataset and get the proper weights for each card? Our formula to reconstruct the count could be as simple as:

Outstanding Issues

Before we get ahead of ourselves, it is important to mention a few nuances that make this solution potentially less ideal:

  • Do we add a bias term? If we really wanted to, we could enforce the bias term to be zero. However, it is worthwhile to include the bias term as it has an intuitive interpretation. Of course, we’ll have to shift our perspective on evaluating count a little, but those details will be explained more later on.
  • Is this data independent? By playing out all hands in a Blackjack shoe, we can guarantee that the data from one event that follows another will not be independent. This dependence is why counting is valuable in the first place, but it also appears to be an obstacle in fitting the regression. We can alleviate this by randomly selecting a single hand from each simulated shoe, as events across shoes are, in theory, independent. Of course, this increases the computational workload as an individual could play out approximately 40–50 hands in a single shoe, and we’re limiting our overall throughput. While I’ll leave the impact of this dependence at scale for future analysis, the summary is that, at scale, this dependence is a minor issue.
  • What about multicollinearity? To make matters worse, we should note that the features would undoubtedly show an abnormal amount of multicollinearity. The intuition is that as one progresses through a shoe, the count for each card type will increase at a similar rate, and the most common states will be those where all the features are roughly the same. Highly correlated features cause problems as they can undermine any stability in estimating statistical significance. We will address the multicollinearity issues by simulating an ample amount of hands, ensuring that the coefficients have converged, but we should keep in mind that the feature matrix is somewhat ill-conditioned in this setting.

Simulation Structure

To fit our regression, we first need to generate data that closely represents standard blackjack play, and therefore a simulator is required. While there were bits and pieces of blackjack programs written in various languages across the internet, most lacked the depth that I needed, such as splitting cards and tracking hand data. Therefore, I ended up throwing together a quick simulator, which can be found on GitHub HERE.

To summarize the code, it proceeds through a shoe, logging the pre-hand counts and post-hand outcomes. Decisions made by the system follow a hard-coded strategy for standard play; in this scenario, we are not asking the system to learn how to play more efficiently as the count changes — the predicted expectation for the upcoming hand is the goal.

Note that there are many variations of Blackjack rules, but for my simulation program, I have adopted these:

  • Six decks
  • One-deck cut, shoe deals out five decks before reset (~83% penetration)
  • Dealer stands on soft seventeen.
  • Double down is allowed after splitting.
  • Resplits are permitted to a total of four hands.
  • Split aces will receive one card each without resplitting.
  • Insurance and surrender options are not available.
  • Natural Blackjack pays 3:2; if tying a natural with the dealer, there is no payout.
  • Only a single player resides at the table.

For the most part, these are standard rules, although swapping out specific rules for others would require minimal changes to the code.

Regression Results

Once we’ve generated the game state and outcome for millions of hands, it is time to fit our model. As mentioned earlier, since counting has a linear structure, this part isn’t too complex; however, there is one thing to note. While there are thirteen different cards, only ten different values exist as 10, J, Q, and K are all worth the same. We could fit the regression on all thirteen of these features, but the four cards mentioned above end up with equivalent coefficients. Therefore, I’ve chosen to combine the counts of these cards into one to save a few degrees of freedom. From there, fitting the model follows the standard procedure as detailed below:

The approximate output for the intercept and coefficients are:

We can translate the initial bias (intercept) as the expected gain on a bet of 1 for a hand where the shoe is fresh or the count is neutral. Since the house has the upper hand, it shouldn’t be too surprising that the intercept is negative. This bias term gives us the best understanding of how “unfair” a particular set of rules is in Blackjack. In this simulation, we expect to lose .0226 in the starting hand; as we see additional cards, that expectation changes based on the weights of each card’s coefficient. Looking over the coefficients above, if previous hands have shown multiple As and 10s, that is good for the dealer, while all other cards are better for the player. Thus, the total card value must outweigh the initial bias for the game to swing in favor of the player. Once this happens, the player places the maximum bet their bankroll strategy suggests. For the scope of this post, we can assume that in cases where the expectation is less than 0, the player bets the minimum and when the expectation is greater than 0, the player bets the maximum. It is essential to call out that in traditional counting systems, the count starts at zero, whereas here we have started the count at a negative value. Most systems accommodate starting at zero by using a predetermined range to assess whether the hand favors the player. In some systems, this value is anything greater than a count of one.

Regressing the Regression

It may seem like we’ve already solved the problem, but there is an additional caveat that traditional counting systems call out and address. We have been keeping track of the running count, but this is not the same thing as the true count, which is a better indicator as to if the upcoming hand will be won by the player or not. The true count is effectively a normalized version of the running count that attempts to understand the strength of a count given the current depth into the shoe. For example, a large positive count is much more powerful when fewer cards are left, when the density of player advantaged cards is high.

Calculating the true count in a traditional scenario is relatively simple; take the running count and divide it by the rough estimate of how many decks remain in the shoe. For example, if the count is +4 and four decks remain, the true count is +1, which holds the same advantage as if the count was +1 and only a single deck remained.

We can see evidence of this if we carry out a regression using the running count from previous steps and adding an interaction term with the total number of cards played. The additional regression can be created by tacking on this code:

Note that in this situation the bias term remains the same; we had removed that from the running count before performing this regression. However, the coefficient for the interaction term is ~.00669, meaning that as we deal more cards from the shoe, the value of the running count becomes more impactful. We can infer that the running count is equivalent to the true count once the dealer has removed 1/.00669 or ~150 cards from the shoe; half of the cards from a six-deck shoe. Also, as we approach the end of a shoe, the true count is approximately twice that of our running count. Thus, it might be easier to double all of our running count coefficients and normalize by taking the current penetration of the shoe (anywhere from 0 to 100%) than trying to recall that half of a shoe means the true count is 100% of the running count. The newly doubled values are shown below:

Integer Translation

Technically, the intercept and coefficient weights presented above are an optimal way to count for betting efficiency given the Blackjack rules we enforced earlier. However, it may be helpful to translate these values back into whole numbers. The easiest way to do this is to change each decimal number to an integer — this would take the form of:

A more feasible set of numbers for human consumption and comparison to already existing counting systems would be worthwhile as well. One balanced approximation is shown below:

What is peculiar about this is if you glance back at the Hi-Lo counting system introduced earlier in the post, you’ll find that this one is relatively similar. The only values that vary are 7, 8, and A; instead of being neutral, 7 and 8 now add to the count, while an Ace is three times more valuable to the player. If we examine a more extensive list of counting systems, Aces are often positive or at least neutral, but they never take on a value this high compared to other cards. So why is our assignment to Aces so much different? I would speculate that this has to do with our sole focus on betting effectiveness while ignoring play efficiency. Aces are incredibly effective in creating hands that require no other decisions, such as a Blackjack or soft hands where the decision will not bust the player. These properties suggest that when focused on play efficiency, there is little value in tracking Aces. But since Aces are so valuable to betting efficiency, the system tries to balance these two components as best it can. With that said, our findings are still surprising as Hi-Lo itself is heavily focused on betting efficiency, and Aces keep a relatively tame valuation, but perhaps only a -1 is assigned to keep the system simple.

Summary

There is much room for expanding on this work in the future. While this post constrained itself to a simple linear model to mimic an actual counting system, nothing holds us back from fitting more expressive models. Our ability to predict the actual outcome of a hand would likely increase if we considered interactions, but this would destroy the human counting aspect entirely. Additionally, as pointed out, this system does not have a reinforcement learning component, and therefore basic strategy does not adapt with the count. The next logical step would be to set up the system to learn an adequate policy across all aspects of the game; betting strategy, counting system, and effective play. If this were available, we could also substitute in current counting systems to assess their strengths, especially for playing efficiency. Finally, there are some statistical arguments that we simply hand waved, such as the overwhelming amount of multicollinearity and data dependence. It would be interesting to give more details on the impact or lack thereof, that this has on our results at different scales. Look out for future posts that might touch on any of these topics!

Unless noted, all images in this post are by the author.

This site only collects related articles. Viewing the original, please copy and open the following link:The Perfect Count for Beating the House in Blackjack by Riley Howsden Medium

🔥 🎉 blackjack strategy card 🎈
🔥 Latest Articles 🎰 🥳 Popular Articles 🎶
😏 Recommended Articles 🎺
# Article Title Keyword Article Link Article Details
WPT Global