Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: [email protected]
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Publication

Can You Actually Beat the Dealer in Blackjack? — Simulation of Most Popular Strategies
Data Science   Latest   Machine Learning

Can You Actually Beat the Dealer in Blackjack? — Simulation of Most Popular Strategies

Last Updated on July 14, 2024 by Editorial Team

Author(s): Eram Khan

Originally published on Towards AI.

In this article I explore if it is actually possible to beat the blackjack dealer using strategic thought. Of course, the underlying idea here is to show the use of simulation and how a game can be modeled mathematically. (But please do feel to try out any of below mentioned strategies if interested!)

The framework discussed below implements a blackjack game simulation and compares the performance of a few selected counting strategies.

Knowledgeable Blackjack players are able to beat the casinos using a technique called “card counting”. Card counting is technically legal, however a casino reserves the right to deny entry to any individual they suspect of using this skill to their advantage.

A statistical analysis is done on these strategies simulating multiple independent blackjack games. Blackjack, as most games in Casino, is heavily dependent on luck. Without counting cards or using any strategy, it is almost always the dealer that gets an advantage.

While, per the rules and design of the game, chances of winning are less than 50%, just following the well-known “Basic Strategy” for counting cards can decrease the advantage of the house and increase the probability of winning to ~50%. There are various Blackjack strategies developed and taught all over the world, this analysis builds a system to compare these strategies and determine which is the most profitable approach. Multiple independent blackjack games are thus simulated to understand the profit and loss in various scenarios. On comparison, Hi-Opt I and Hi-Opt II have been identified to maximise win expectation.

Background and Description of Problem:

Rules of the Game: Blackjack allows for multiple players. Each players plays the Casino dealer, and each game is independent. Each game may contain multiple rolls. In a roll, using the cards, both the player and the dealer try to generate highest number possible without crossing the sum of “21”. Crossing this threshold indicates going “bust”, meaning you have lost. As the player goes first, there is always a slight advantage to the dealer. Please find below, a summarized view of common scenarios during the game.

Table 1: Basic rules of Blackjack
  • The players’ cards are dealt face up. One of the dealer’s cards is dealt face down while the other is dealt face up.
  • Each card from 2 to 10 has a value corresponding to its number.
  • The face cards are worth 10
  • An ace is worth either 1 or 11, depending on what is advantageous during the game.
  • A player can either decide to “Hit” that is request for another card or “Stand” that is keep current cards during a game.
  • A player can also “Double” the amount of bet made during the game and receives just one additional card.
  • If the player is dealt a pair of same cards, they can “Split” their hand. That is, they can play two separate games using their cards.

While exploring these strategies, this analysis explores two major areas,

  1. Identifying point of convergence for expected wins in independent blackjack games (After how many simulations can winning probability be determined)
  2. Explore and compare different card counting strategies

In the upcoming sections, scope and assumptions are defined, followed by brief explanation of the development architecture, describing the logic used to simulate the game of blackjack with different strategies. Key findings are then described that set forth the results of the analysis on Black Jack simulation strategies.

Key Assumptions:

I focus on just one player and the dealer. To reduce complexity, options like splitting, doubling down, surrendering and insurance are not considered. A six-deck card system has been considered for this simulation. A player is awarded 1 point on each win, however in case of “Blackjack” the reward is 3/2 points.

Ten counting strategies are considered for this analysis. Please find below the values associated with each card for different strategies. In case of “No Strategy”, no counting strategy is followed, apart from basic Blackjack Strategy.

Table 2: Card values for different blackjack counting strategies

Development and Architecture:

Implementation is primarily done in Python using Jupyter Notebook (Fig. 1). Card values for each card of the deck is taken as input for each strategy using a CSV file. The Blackjack simulation script inputs this information along with “number of simulations” to be run. Multiple blackjack games are then simulated and expected winning is logged.

Figure 1: Overall framework architecture

Script Overview:

  1. Counting strategies CSV and “number of simulations” to be run are input by the user.
  2. Cards are dealt to the player and the dealer.
  3. Running count and True count (based on values defined in strategies.csv) are maintained based on open card count throughout the game.
  4. In case no blackjack is achieved by either player or dealer both have an option to “Stay” or “Hit”.
  5. Player choice is determined by threshold on true count of currently open cards.
  6. A game ends if < 12 cards are left in the deck or < 1 card is left in the last roll.
  7. Winnings/Losses are determined at end of each roll and count is logged.
  8. 2000 blackjack games are played using each strategy.

Full code is available here: https://github.com/eramkhan94/blackjack_simulator

Key Findings

  1. Identifying point of convergence: Blackjack games were simulated 10,000 times with No Strategy. Expected winnings were logged and plotted (Fig. 2). The simulation reached convergence with a predefined delta of 0.01, between the average expected win of previous 200 iterations (i.e. 1200–1400) and next 200 iterations (i.e. 1400–1600), reaching ~1600 games. Additional 400 iterations were added as a buffer to account for variance in convergence of different strategies. Thus, for further analysis and comparison, each strategy was simulated 2000 times and expected winnings were observed (Fig. 2).
Figure 2: Expected wins on running 10,000 simulations following no strategy

2. Strategy Analysis and Comparison: To further compare strategies, 2000 games were simulated for each counting strategy 30 times and results were logged. The expected winnings for each strategy were compared against No Strategy using a one way ANOVA test. For six strategies out of ten, a p-value of less than 0.05 was observed indicating that the mean of expected winnings was significantly different than the expected winnings mean when No Strategy was followed (Fig. 4).

Figure 3: Expected wins for different counting strategies in 2000 game simulations
Figure 4: F-statistic for one way anova test on expected wins for each strategy compared to No Strategy
Figure 5: Box Plot representing distribution of Expected Wins for different strategies

On further analysing the distribution of expected wins (Fig. 5), it is found that Hi-Opt I has the highest expected wins at 50.43, followed by Hi-Opt II (50.31), Halves (50.31), Wizard Ace (50.30), Red 7 (50.297) and Zen (50.291). Other strategies did not yield significantly different results than “No Strategy”. However all strategies resulted in higher expected wins compared to “No Strategy”. Highest variance in result was observed for “Hi-Opt I”, “Halves” and “Omega II”.

Conclusion:

Counting strategies do offer an edge compared to an intuitive game in Blackjack. Hi-Opt I has resulted in maximum expected gain. In further analysis assumptions on player moves can be relaxed. The optimisation for player moves like “splitting”, “doubling down” will further generalise this framework and aid in developing and testing new blackjack strategies. Relaxing these assumptions may also result in an increased difference in wins when using a counting strategy and some counting strategies might yield higher expected wins.

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI

Feedback ↓