Hugues Hoppe — [Open in Colab] [in Kaggle] [in MyBinder] [in Deepnote] [GitHub source]
Blackjack — "the most widely played casino banking game in the world".
Goals:
-
Solution methods for both:
-
Probabilistic analysis of blackjack actions and outcomes under many strategies, and
-
Monte Carlo simulation for cut-card effects and precise split-hand rewards.
-
-
Support for many rule variations (13 parameters including number of decks, dealer hits soft 17, cut-card, ...).
-
Optimal action tables for basic strategy under any rules, reproducing Wikipedia and WizardOfOdds results.
-
Six strategies with progressively greater attention, from basic strategy to full composition dependence.
-
Computation of house edge under any rules, with either basic or composition-dependent strategies.
-
Comparisons with online hand calculator and house edge calculator results.
-
Novel analysis and visualization of the cut-card effect and its surprising oscillations.
-
Open-source Python, sped up with jitting (~30x) and multiprocessing (~10x), simulating
$\sim 10^{8}$ hands/s. -
GPU implementation using
numba.cuda, simulating$\sim 10^{10}$ hands/s.
Versions:
- 1.0 (March 2022): use probabilistic analysis for basic strategy tables and approximate house edge.
- 2.0 (July 2022): add Monte Carlo simulation, hand analysis, and cut-card analysis.
- 3.0 (January 2025): add CUDA implementation of simulation.
- 3.1 (October 2026): fix bugs in simulating split hands and shoe ends; regenerate all results.
Running this Jupyter notebook:
- The notebook requires Python 3.10 or later.
- We recommend a Jupyter server on a local machine with a fast multi-core CPU and ideally an
NVIDIA GPU.
(The notebook can also be executed on a Colab server, where it greatly benefits from a CUDA GPU.) - Install JupyterLab on Linux or macOS, or on Windows within
Windows Subsystem for Linux,
because the multiprocessing uses
fork. - Open the notebook (
blackjack.ipynbfile); its first cells install the required packages. - Evaluate all cells in
Code libraryand then selectively evaluateResults. - Adjust the
EFFORTglobal variable (or set theEFFORTenvironment variable) to trade off speed and accuracy. - Alternatively, after installing the packages listed in its first code cell, run the paired
script directly, e.g.,
EFFORT=1 python blackjack.py.
References:
- https://en.wikipedia.org/wiki/Blackjack
- https://wizardofodds.com/games/blackjack/basics/#rules
- https://www.casinoguardian.co.uk/blackjack/
- https://wizardofvegas.com/guides/blackjack-survey/
- https://www.blackjackinfo.com/
- https://www.onlinegambling.com/blackjack/odds/
- https://www.onlineunitedstatescasinos.com/las-vegas/blackjack/
- https://en.wikipedia.org/wiki/Gambling_mathematics
- https://github.com/johntelforduk/blackjack -- Python simulator to evaluate house edge for various strategies.
- First reddit post
(See also references in Tables for basic strategy, Hand calculators, and House edge calculators.)