Design Blackjack
🃏 What is blackjack? Blackjack is a card game where each player plays against the dealer, not against each other. Everyone tries to get a hand closer to 21 than the dealer without going over. Players decide when to take more cards; the dealer has no choices at all and follows a fixed rule. Bets are paid when the round ends.
Interviewers like blackjack because it looks like "just a card game" but hides three real design questions. How do you count a hand when an ace can be worth 1 or 11? How do you stop a player from hitting when it is not their turn, or betting in the middle of a round? And where do the rules that casinos change (the dealer's rule, the payout) live? The same prompt also comes up as "design an online blackjack table". That is the same design with more seats and a clock: the table already runs several seats in turn and hides the dealer's second card, and we cover joining, leaving, turn timers and concurrency in the Extensibility section.
Requirements
"Design a game of blackjack. A few players sit at a table with a dealer. Players bet, play their hands, and get paid."
This prompt is short on purpose. Players who have never sat at a casino table do not know the rules, so asking about them is part of the job, not a sign of weakness.
Clarifying Questions
You: How many players, and do they play against each other?
Interviewer: Up to four seats. Each player plays only against the dealer. Players act one at a time, in seat order.
You: Which actions can a player take?
Interviewer: Hit (take a card), stand (stop), and double down (double the bet, take exactly one more card, stop). Skip splitting and insurance for now.
You: What does the dealer do?
Interviewer: The usual rule: the dealer draws until the hand is worth at least 17, then stands. Stand on every 17, including a "soft" 17 with an ace counted as 11. Some casinos make the dealer hit a soft 17, so that rule may change.
You: How are bets paid?
Interviewer: A win pays even money. A blackjack, meaning 21 with your first two cards, pays 3 to 2. A tie is a push: you get your bet back. If the dealer also has blackjack, a player blackjack is a push and everyone else loses straight away.
You: How do we shuffle? If the deck is random, it is hard to test.
Interviewer: Good point. Take the order of the cards as input. The real table would shuffle before it hands us that order.
You: When are chips taken from the player?
Interviewer: When the bet is placed. You cannot bet more than you have, and you can only bet between rounds.
You: Is this one table in one process, or an online table with people joining from their phones?
Interviewer: Start with one table and one caller. Keep the online version in mind; we will get to it.
The dealer question is the one to push on. "The dealer draws to 17" leaves out the soft 17 case, and the answer changes which cards come out of the shoe. Ask for the exact stopping rule, and notice that the interviewer told you it changes between casinos. That is a hint about where to put an extension point.
💡 Interview tip: When a game has a random part, ask to inject it. Passing in the card order (or a seeded shuffler) makes every round repeatable, so you can trace an exact scenario at the end, and so can the practice tests.
Final Requirements
- A table has up to four seats. Each player has a chip balance.
- Between rounds, players place bets. A bet is taken from the balance at once. A bet must be at least 1 and at most the balance, and a player bets at most once per round.
- A round starts with a deal: two cards to each betting player and two to the dealer, one card at a time. The dealer's second card stays hidden while players play.
- Hand value: number cards count their number, face cards count 10, and an ace counts 11 unless that would bust the hand, then 1. Over 21 is bust. 21 with the first two cards is a blackjack.
- If the dealer has a blackjack, the round ends right after the deal.
- Otherwise players act in seat order: hit, stand or double down. Only the current player can act. A turn ends on stand, after a double down, or when a hit reaches 21 or more. A player with a blackjack is skipped.
- Then the dealer draws until the hand is at least 17 (standing on soft 17), unless every player is already bust or has a blackjack.
- Each hand is settled as a win (paid 1 to 1), a blackjack (paid 3 to 2, rounded down), a push (bet returned) or a loss. A bust always loses.
- Anyone can see whose turn it is, the dealer's visible cards, each balance and each player's last result.
Out of scope
- Splitting pairs, insurance and surrender (splitting comes back in Extensibility).
- Side bets, table limits and the cut card that triggers a reshuffle.
- Real money, accounts and logins.
- Several callers at once (we come back to this in Extensibility).