Interactive blackjack basic strategy calculator for any rule combination. The strategy is computed using Expected Value (EV) calculations. House edge is verified using Monte Carlo simulation on GPU with CUDA.
Live Demo: https://hankhsu1996.github.io/blackjack-basic-strategy/
# Generate strategy JSON files
uv run python -m scripts.generate_strategies
# Start dev server
cd web && npm run devOpen http://localhost:5173/blackjack-basic-strategy/
├── src/blackjack/ # Python strategy calculation
│ ├── config.py # GameConfig dataclass
│ ├── cards.py # Card values, probabilities
│ ├── dealer.py # Dealer outcome distribution
│ ├── evaluator.py # EV calculations
│ ├── house_edge.py # House edge calculation
│ ├── strategy.py # Optimal action selection
│ ├── tables.py # Strategy data generation
│ └── renderers.py # Data structures
├── cuda/ # GPU Monte Carlo simulation
│ ├── monte_carlo.cu # CUDA implementation
│ └── Makefile # Build configuration
├── scripts/
│ └── generate_strategies.py # Generate JSON for web app
└── web/ # Svelte + Tailwind + DaisyUI
├── src/
│ ├── App.svelte
│ └── lib/
│ ├── components/ # UI components
│ ├── stores/ # Svelte stores
│ ├── types/ # TypeScript types
│ └── utils/ # Color utilities
└── public/strategies/ # Pre-computed JSON (generated)
uv sync # Install dependencies
uv run ruff check . # Lint
uv run ruff format . # Formatcd web
npm install # Install dependencies
npm run dev # Dev server
npm run build # Production builduv run python -m scripts.generate_strategiesGenerates strategy JSON files for all rule combinations to web/public/strategies/.
For verifying house edge calculations with high precision:
cd cuda
make # Build (requires NVIDIA GPU + CUDA toolkit)
make test # Quick test: 1B hands
make run # Standard: 10B hands (~±0.002%)
make precision # High precision: 40B hands (~±0.001%)See cuda/README.md for setup instructions.
| Parameter | Default | Description |
|---|---|---|
| num_decks | 6 | Number of decks (0 = infinite) |
| dealer_hits_soft_17 | False | H17 vs S17 rule |
| double_after_split | True | DAS allowed |
| resplit_aces | False | RSA allowed |
| dealer_peeks | True | Dealer checks for blackjack |
S- StandH- HitD/Dh/Ds- Double (or Hit/Stand if not allowed)P/Ph- Split (or Hit if not allowed)
GameConfig → EVCalculator → BasicStrategy → StrategyTables → JSON/Renderer
↓
DealerProbabilities
- GameConfig: Immutable dataclass holding all rule parameters
- DealerProbabilities: Calculates P(dealer final total | upcard)
- EVCalculator: Core EV calculations using (total, soft_aces) state
- HouseEdgeCalculator: Computes house edge for a given configuration
- BasicStrategy: Determines optimal action by comparing EVs
- StrategyTables: Generates strategy data (
StrategyData)
Hands are represented as (total, soft_aces) tuples for efficiency:
total: Hand value (4-21)soft_aces: Number of aces counted as 11 (0 or 1)
This reduces state space from exponential (card combinations) to ~40 states.
For finite decks (num_decks > 0), the calculator uses composition-dependent probabilities:
- Card draw probabilities are adjusted for known removed cards (player's hand + dealer upcard)
- Dealer outcome probabilities are recalculated with adjusted deck composition
This matches real-world 4-8 deck basic strategy charts. For infinite deck (num_decks = 0), standard probabilities are used.
- Svelte 5 - Reactive UI framework
- Tailwind CSS - Utility-first styling
- DaisyUI - Component library
- Vite - Build tool
- Pre-computed strategies: 96 JSON files cover all rule combinations. Faster than runtime calculation.
- HSL colors: Easy to adjust whiteness/saturation for accessibility.
- Responsive layout: Desktop shows sidebar + horizontal tables; mobile uses collapsible config.
GitHub Actions automatically:
- Generates strategy JSON files
- Builds Svelte app
- Deploys to GitHub Pages
<Summary starting with verb, 50 chars or less>
- Bullet points (2-5)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>