From Excel to Web: Building a Real-Time Blackjack Card Counting Calculator
From Excel to Web: Building a Real-Time Blackjack Card Counting Calculator
A couple of years ago, I built an Excel spreadsheet out of pure curiosity. The goal was simple: calculate the exact expected value (EV) and optimal strategy for any blackjack hand, accounting for the current composition of the deck.
What started as a weekend project became something more interesting when I realized: this is exactly the kind of software online casinos use internally to detect advantage players.
Today, I'm launching Advantage Player — a web-based version that anyone can use to understand the mathematics behind card counting.
The Excel Origins
The original spreadsheet was built on probability theory and combinatorics. For any given shoe state (number of remaining cards of each rank), it could:
- Calculate running count and true count (Hi-Lo system)
- Compute exact win probabilities for hit, stand, double, split
- Generate complete strategy tables based on current deck composition
- Track expected value as cards are dealt
The math was straightforward but tedious. Excel's array formulas made it possible, but barely. Each cell recalculated probabilities based on hypergeometric distributions. It worked, but it was slow and unwieldy.
Why Casinos Care
Online casinos don't just track your wins and losses. They track:
- Bet correlation with true count — Are you betting more when the count is high?
- Strategy deviations — Are you making plays that only make sense at high counts?
- Session patterns — Do you leave when the count goes negative?
They use software similar to what I built to analyze thousands of hands and identify skilled counters. It's an arms race: players study the math, casinos study the players.
The Web Version Challenge
Porting this to the web wasn't just about translating Excel formulas to Python. The real challenges were:
1. Real-Time Performance
Excel could take seconds to recalculate. A web app needs to respond in milliseconds. Every card dealt triggers:
- Shoe state update (13 card ranks to track)
- Probability recalculations for all possible actions
- Strategy table regeneration (3 tables × 10 dealer cards × ~50 player hands)
- Expected value computation
Solution: Pre-compute probability matrices, cache intermediate results, and use numpy for vectorized calculations. Response time: <50ms per card.
2. Composition-Dependent Strategy
Basic strategy assumes infinite decks. Real advantage play accounts for exact card removal effects. For example:
Player has 16 vs Dealer 10
Basic strategy: Always hit
True count +4: Stand
But what if the shoe is ten-rich vs ace-rich?
The answer changes based on which specific cards remain. The web version calculates this dynamically.
Solution: Build a mini-simulation engine that computes EV for each action by recursively considering all possible next cards, weighted by their actual remaining probability.
3. State Management
Unlike Excel's inherent state, a web app needs to manage:
- Multiple concurrent users
- Session persistence across page reloads
- Shoe state across multiple API calls
- Demo vs paid user rate limiting
Solution: Server-side session management with Redis, PostgreSQL for access control, and careful API design to keep the client thin.
4. Access Control Without Ruining UX
Card counting tools are valuable. But I wanted to offer a demo that's actually useful while still incentivizing upgrade.
Solution: Demo users get: - Full calculator interface - Real strategy calculations - But: 50 cards per session, 1-minute cooldown between cards
This lets you genuinely try the tool (enough to count through a couple hands) but not run full sessions.
Technical Stack
The production site runs on:
- Backend: Flask (Python)
- Database: PostgreSQL + Redis
- Frontend: Vanilla JS + Tailwind CSS
- Deployment: Docker on Hetzner Cloud
- Auth: Google OAuth (because email/password is so 2010)
Key libraries:
numpy # Fast probability calculations
sqlalchemy # ORM for user/session management
authlib # OAuth2 without the pain
stripe # Payments (surprisingly good API)
The Math (For the Curious)
The core calculation is Expected Value for each action:
EV(action) = Σ P(next_card) × Value(resulting_hand)
Where Value(resulting_hand) is recursively calculated based on optimal subsequent play.
For a 6-deck shoe with specific cards removed, computing this naively would require:
13 possible next cards
× recursive depth of ~10
× branching factor of ~3 (hit/stand/double)
= ~390 scenarios per action
× 4 possible actions
= 1,560 calculations per hand analysis
Optimization: Memoize intermediate results, vectorize with numpy, and use probability cutoffs (ignore scenarios with P < 0.001).
What Makes It Different
Unlike basic strategy charts you can find anywhere, this tool:
- Updates strategy in real-time as you input dealt cards
- Shows exact EV for your current situation (+2.3% edge vs -0.5% disadvantage)
- Accounts for composition not just count (more aces vs more tens matters)
- Explains recommendations ("Double — strong position with 11, maximize bet")
It's the difference between "follow this chart" and "understand why this is optimal right now."
Lessons Learned
What Worked
- Server-side calculations: Keep the logic secret, prevent manipulation, reduce client-side complexity
- Demo access: Let people try before they buy. Worked better than I expected
- OAuth only: No password reset emails, no password requirements, instant signup
What Surprised Me
- People want the learning tool more than the advantage: Many users just want to understand the math, not actually count cards
- Mobile usage is high: 40% of users on mobile. Had to optimize touch interactions
- Count system variations: Hi-Lo dominates, but there's surprising interest in Omega II and Hi-Opt II
What I'd Do Differently
- Use pre-compiled Tailwind: The CDN version is convenient but slow. Costs ~2 seconds on initial load
- Add betting recommendations: Users keep asking "how much should I bet at a given EV?"
- Team play features: Let a group of users track multiple tables, and collaborate on aggregate bet sizes when the EV is positive.
Try It Out
The calculator is live at advantage-player.com. Demo access is free — you can track 50 cards per session to get a feel for how it works.
Fair warning: Card counting is legal but casinos don't like it. This tool is for: - Understanding the mathematics of blackjack - Training before heading to a casino - Analyzing your own play decisions - General curiosity about probability and game theory
Not for: - Using in an actual casino (they'll ask you to leave) - Beating online blackjack (they shuffle every hand) - Getting rich quick (advantage play is work, not magic)
Open Questions
I'm curious what the HN crowd thinks:
- Should I open-source the calculation engine? Casinos already have this, but would it hurt the business model?
- Alternative monetization? Currently paid access or affiliate signup. Other ideas?
- What other games have interesting math? Poker is player-vs-player. Craps is pure negative EV. What else is worth analyzing?
Built with curiosity, maintained with coffee. Check it out and let me know what you think.
Technical details, code snippets, or specific questions? Happy to discuss in the comments.