Skip to content

Repository files navigation

Blackjack Solver

Exact blackjack solver using backward induction. Computes mathematically optimal play by solving the full decision tree via dynamic programming — no heuristics, no approximations beyond two standard, documented ones.

Features

  • Exact backward induction — every possible future card sequence and its optimal continuation is evaluated
  • Per-hand solver — optimal action + EV for any hand vs any dealer upcard
  • Overall house edge — probability-weighted enumeration of all possible initial deals
  • Strategy chart generator — color-coded basic strategy with diff highlighting when cards are removed
  • Web dashboard — interactive UI with hand analysis, dealer outcomes, shoe composition, and strategy charts
  • Web Worker — all computation runs in a background thread, UI stays responsive

Supported Rules

RuleOptions
Deck count1–8
Dealer soft 17Hit (H17) or Stand (S17)
Dealer peekOn (American) or Off (European/ENHC)
Double after splitYes / No
BJ payout3:2 (default), 6:5, or custom
Dead cardsArbitrary card removal from shoe

Accuracy

Verified against the Wizard of Odds house edge calculator (no resplit baseline):

ConfigurationPublishedSolverDifference
8-deck H17 peek DAS-0.6993%-0.7018%0.0025%
6-deck H17 peek DAS-0.6690%-0.6723%0.0033%
2-deck H17 peek DAS-0.4244%-0.4343%0.0099%
1-deck S17 peek DAS+0.1531%+0.1362%0.0169%

All basic strategy decisions match published tables — every hard total, soft total, pair, and boundary case verified.

Known Approximations

Two standard approximations are used, consistent with professional-grade solvers:

  1. Precomputed dealer outcomes — Dealer outcome probabilities are computed once from the initial shoe (after removing visible cards), not recomputed as the player draws. Error: ~0.003% for 8 decks, ~0.017% for 1 deck.

  2. Split hand independence — Both split hands are solved against the same shoe. Cards drawn to one hand don't affect the other hand's shoe composition. Negligible error for 6+ decks.

Not Yet Implemented

FeatureHouse Edge ImpactNotes
Late surrender~0.08%Changes optimal play for 15 vs 10, 16 vs 9/10/A
Resplit (up to 4 hands)~0.05%Would require recursive split solver
Double restrictions (9-11, 10-11)~0.09–0.18%Some casinos restrict which totals can double
OBO for no-peek~0.11%"Original Bet Only" variant where only base bet is lost to dealer BJ

Architecture

blackjack-solver.js Core solver (backward induction)
solver-worker.js Web Worker wrapper (routes EV + chart requests)
blackjack-calculator.html Dashboard UI (hand input, results, strategy chart)
strategy-chart.html Strategy chart renderer (loaded in iframe)
server.js Dev server (port 8000)

Data Flow

Dashboard → postMessage → iframe (strategy-chart.html)
→ Web Worker (solver-worker.js)
→ generateStrategyChart() / solveOverallEV()
→ solve() × N hands (backward induction per hand)
→ returns results
→ iframe renders tables → notifies parent

Usage

node server.js
# Open http://localhost:8000/blackjack-calculator.html

Or run the solver directly:

node blackjack-solver.js

Legacy Files

  • blackjack-odds.js — Original heuristic-based odds calculator (superseded by blackjack-solver.js)
  • blackjack-simulator.js — Monte Carlo simulation engine using the old odds module

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages