Expected-Value (EV) Blackjack Simulation, Strategy Optimization, and Random Forest Decision Modeling.
Blackjack is a foundational problem in applied probability and sequential decision theory, where every hand presents an optimal mathematical choice based on expected value (EV). Bust-or-Trust is a data science framework that models, simulates, and optimizes Blackjack decision-making. By simulating 150,000+ stochastic hand permutations across all player-dealer states, this project calculates empirical expected values for every available action (Hit, Stand, Double), constructs an optimal strategy matrix, and trains a supervised Random Forest Classifier to predict the highest-EV play in any table state.
- Large-Scale Stochastic Hand Simulation: Synthesized a dataset of 150,000+ Blackjack hand trajectories tracking player starting values (4–21), dealer face-up cards (2–11/Ace), player actions, and payoffs.
-
Expected Value (EV) Computation: Quantified expected returns (
$EV \in [-2.0, +2.0]$ ) for every action across all state pairs to identify profitable vs. loss-minimizing decisions. -
Empirical Strategy Table: Generated a complete lookup table mapping every
(Player_Hand, Dealer_Upcard)state to its mathematically optimal action. - Decision Heatmap Visualization: Rendered 2D Seaborn heatmaps illustrating decision boundaries, bust vulnerabilities, and optimal play zones.
-
Machine Learning Action Classifier: Trained a Scikit-Learn
RandomForestClassifier(100 estimators) achieving 94% test accuracy in predicting optimal game decisions. - Empirical Game-Theoretic Insights: Verified non-intuitive classical basic strategy principles through data-driven expected value convergence.
| Layer | Tools & Libraries |
|---|---|
| Language & Environment | Python 3.10+, Jupyter Notebook |
| Data Processing & Analytics | Pandas, NumPy |
| Machine Learning | Scikit-Learn (RandomForestClassifier, train_test_split, metrics) |
| Data Visualization | Seaborn, Matplotlib |
| Datasets & Tables | blackjack_simulation.xls, blackjack_ev_table.xls |
Bust-or-Trust/
├── blackjack_ev_simulation.ipynb # Main Jupyter notebook with simulation, EV tables & RF model
├── blackjack_simulation.xls # Simulated hand outcomes dataset (150k+ records)
├── blackjack_ev_table.xls # Aggregated EV lookup table per state-action pair
├── blackjack_strategy_heatmap.png # Generated strategy heatmap visual
├── requirements.txt # Python dependencies
├── .gitignore # Ignored cache and virtual environment files
├── LICENSE # MIT License
└── README.md # Project documentation
git clone https://github.com/mayankt411/Bust-or-Trust.git
cd Bust-or-Trust
# Create and activate a virtual environment
python -m venv .venv
# On Windows (PowerShell):
.venv\Scripts\Activate.ps1
# On Linux / macOS:
# source .venv/bin/activatepip install -r requirements.txtjupyter notebook blackjack_ev_simulation.ipynbThe generated heatmap illustrates the transition boundary between Hit, Stand, and Double Down across player totals (4–21) and dealer upcards (2–11/Ace):
Below is an empirical sample extracted from blackjack_ev_table.xls:
| Player Hand | Dealer Upcard | Action | Expected Value (EV) | Sample Count | Optimal Action |
|---|---|---|---|---|---|
| 16 | 10 | Hit | -0.4697 | 1,173 | ⭐ Hit (Minimizes Loss) |
| 16 | 10 | Stand | -0.5737 | 1,173 | |
| 16 | 10 | Double | -0.9395 | 1,173 | |
| 11 | 6 | Double | +0.6480 | 1,173 | ⭐ Double (Maximizes Win) |
| 11 | 6 | Hit | +0.3240 | 1,173 | |
| 11 | 6 | Stand | -0.1620 | 1,173 | |
| 20 | 7 | Stand | +0.7850 | 1,173 | ⭐ Stand (Safe Hold) |
| 20 | 7 | Hit | -0.8210 | 1,173 | |
| 20 | 7 | Double | -1.6420 | 1,173 |
The Random Forest Classifier was evaluated on an unseen 20% holdout test set of state-action scenarios:
Classification Report:
precision recall f1-score support
Double 0.50 0.50 0.50 2
Hit 0.95 0.95 0.95 22
Stand 1.00 1.00 1.00 12
accuracy 0.94 36
macro avg 0.82 0.82 0.82 36
weighted avg 0.94 0.94 0.94 36
Key Finding: In "stiff" hand scenarios—most notably Player 16 against Dealer 10—many intuitive players choose to Stand out of fear of busting. However, our empirical EV simulation demonstrates that Hitting yields an expected value of -0.470 compared to -0.574 for Standing. While both actions are in negative expectation territory, Hitting saves ~10.4% in expected return per hand over the long run, validating the mathematical core of basic blackjack strategy.
- Split and Surrender Rules: Integrate pair splitting and late surrender logic to expand the decision action space.
- Monte Carlo Shoe Depletion: Implement multi-deck card tracking with Hi-Lo running/true count variance analysis.
- Interactive Streamlit Web Dashboard: Deploy an interactive frontend allowing users to input any table situation and receive instant EV distributions and model predictions.
- Deep Reinforcement Learning (DQN): Train Deep Q-Network agents to learn optimal playing policies through self-play reinforcement learning without hardcoded lookup tables.
- Basic Strategy Benchmark Comparison: Systematically benchmark empirical convergence errors against theoretical infinite-deck Markov decision process solutions.
This project is licensed under the MIT License.
