Blackjack Card Game

Casino Card Game Simulation

Design a Blackjack table: a shoe of shuffled decks, hands that count an ace as 1 or 11, bets, hit, stand, double and split, a dealer that follows fixed rules, and the payout.

Overview

Blackjack is a card game played against a dealer. Each player bets, gets two cards, and then draws more cards to get as close to 21 as possible without going over. The dealer draws last and follows fixed rules, so the dealer makes no choices at all. A player who beats the dealer wins the bet; a blackjack (an ace and a ten-point card as the first two cards) pays more.

The problem looks like a toy, but it tests real design skills. Can you count an ace as 1 or 11 without a bug? Can you stop a player from hitting when it is not their turn? Can split, which turns one hand into two in the middle of play, fit your model without special cases everywhere? And can a test control which cards come out of the shoe, so every rule can be checked with exact numbers?

A strong answer scopes the rules first, draws the round as a small state machine, puts the ace logic in the hand, and keeps the dealer's rule and the payout ratio as configuration.

Scoping the problem

House rules differ from casino to casino, so ask before you design. Each question below changes the code, and each comes with the answer most interviewers accept.

  • How many decks are in the shoe? This sets the size of the shoe and when to reshuffle. The usual answer is six decks, reshuffled at a cut card.
  • Does the dealer hit a soft 17? This changes the dealer's rule. Make it configurable; the default stands on all 17s.
  • What does a blackjack pay? This is the payout formula. Usually 3 to 2, configurable.
  • Which actions are in scope? Each action is a method and a rule check. Hit, stand, double and split are the core; insurance and surrender are follow-ups.
  • How many hands may a split make? This limits re-splitting. Up to four.
  • How many players sit at a table? This sets the turn order. Several, played in seat order.

Functional requirements

  • A shoe of several 52-card decks, shuffled, and reshuffled between rounds once the cut point is reached
  • place_bet(player, amount) before the deal, within the table limits and the player balance
  • Hand value counts an ace as 1 or 11; detect soft hands, blackjack and bust
  • Player actions on the current hand: hit, stand, double down, split a pair (up to four hands)
  • The dealer follows a fixed rule: stand on all 17s, or hit a soft 17 at tables that use that rule
  • Settle every hand: blackjack pays 3 to 2, a win pays 1 to 1, a tie pushes, a bust loses
  • Several players at one table, played in seat order

Non-functional requirements

  • Correctness: each action is allowed only in its phase and on a hand where it is legal
  • Configurable: table limits, blackjack payout, maximum hands and the dealer rule are settings, not code changes
  • Testable: the shoe is injected, so a test can stack the cards and assert exact balances
  • Money is whole chips (integers), so payouts never suffer floating-point error; 3 to 2 on an odd bet rounds the half chip down, so a real table counts in smaller units or takes only even bets

Interview questions

  • Why does the ace logic live in Hand and not in Card?
  • Walk me through split. What makes it tricky?
  • How do you support house rule variations?
  • How does the shoe decide when to reshuffle, and why only between rounds?
  • Many tables run at once, and players use a phone app. How do you handle concurrency?

Sign up free to read the full topic

More Low-Level Design topics

Start free on Cariara · Coding problems · System design studio