← Questions
Design a blackjack game
0
I was asked this
No reports yet. Sign in to say where you were asked it.
An object-oriented design interview question asked at Amazon. It tests object-oriented design.
Design the object model for a blackjack table: one dealer, several players, a shoe made of several decks, bets, and payouts. Players can hit, stand, double down and split; the dealer follows fixed rules. Write the classes and the main flow of a round in code.
Requirements
- Functional: players join a table and place bets within the table's limits; the dealer deals two cards to each player and to itself (one face down); each player in turn hits, stands, doubles (one more card, bet doubled) or splits a pair into two hands; the dealer then plays by fixed rules (hits below 17, stands on 17 or more); each hand is settled: win pays 1:1, blackjack pays 3:2, push returns the bet, bust loses.
- Aces count as 1 or 11; a hand's value uses the best total that does not bust.
- The shoe holds several decks and is reshuffled when it runs low.
- Non-functional: rules that vary between tables (number of decks, whether the dealer hits soft 17, blackjack payout) are configuration, not code changes; the model is testable with a fixed card order.
Clarifying questions
- How many decks, and when is the shoe reshuffled (a cut card)?
- Does the dealer hit or stand on soft 17?
- Can a player split more than once, and can they double after a split? What about split aces?
- Are insurance and surrender in scope?
- Is this a single-process game, or do players connect over a network?
What a strong answer covers
- Core classes:
Card(rank, suit),Shoe(decks, draw, reshuffle, injectable randomness),Hand(cards, bet,value(),is_soft(),is_blackjack(),is_bust()),Player(chips, list of hands),Dealer,Table(players, shoe, rules),Round(the state machine of one round), andRules(configuration). - Hand value with aces: count every ace as 1, then add 10 once if that does not bust.
- Splitting as creating a second
Handwith its own bet, which is why a player holds a list of hands. - The round as explicit states (betting, dealing, player turns, dealer turn, settlement), so illegal actions (doubling after hitting) are rejected in one place.
- Settlement in integer chip units, with blackjack-versus-21 handled correctly.
- Tests with a stacked shoe for blackjack, push, bust, split and soft hands.
Follow-ups
- Add insurance when the dealer shows an ace.
- Add a player strategy interface so bots can play using basic strategy.
- How would the model change for an online table with a turn timer?
Where it's asked
What it tests
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. New accounts get 5 credits: each one unlocks a question for good.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing
