InterviewDB
Question
Card Game - OOD Deck, Hand, and Turn-Based Game Engine
phone
Question Details
Problem
Design a class hierarchy for a simple turn-based card game. A standard deck has 52 cards (4 suits, 13 ranks). Players are dealt a hand. On each turn, a player plays one card; the highest-rank card wins the trick.
Implement:
python
class Card:
suit: str # HEARTS, DIAMONDS, CLUBS, SPADES
rank: int # 2-14 (14 = Ace)
class Deck:
def __init__(self): ... # 52 cards
def shuffle(self, seed: int): ...
def deal(self, n: int) -> list[Card]: ...
class Hand:
def play(self, card: Card): ...
def has_card(self, card: Card) -> bool: ...
class Game:
def __init__(self, num_players: int): ...
def play_round(self) -> str:
**returns** winner player id
Follow-ups
- How do you enforce that
dealraises an error when the deck runs out of cards? - How would you add a
Trumpsuit that beats all other suits regardless of rank? - Describe how you would serialize mid-game state to JSON for a save/resume feature.
- How do you handle games with wildcards (jokers) that can substitute for any card?
Full Details
Problem
Design a class hierarchy for a simple turn-based card game. A standard deck has 52 cards (4 suits, 13 ranks). Players are dealt a hand. On each turn, a player plays one card; the highest-rank card wins the trick.
Implement:
python
class Card:
suit: str # HEARTS, DIAMONDS, CLUBS, SPADES
rank: int # 2-14 (14 = Ace)
class Deck:
def __init__(self): ... # 52 cards
def shuffle(self, seed: int): ...
def deal(self, n: int) -> list[Card]: ...
class Hand:
def play(self, card: Card): ...
def has_card(self, card: Card) -> bool: ...
class Game:
def __init__(self, num_players: int): ...
def play_round(self) -> str:
**returns** winner player id
Follow-ups
- How do you enforce that
dealraises an error when the deck runs out of cards? - How would you add a
Trumpsuit that beats all other suits regardless of rank? - Describe how you would serialize mid-game state to JSON for a save/resume feature.
- How do you handle games with wildcards (jokers) that can substitute for any card?
Free preview. Unlock all Affirm questions →
About This Question
This is a reported interview question from a affirm interview during the phone round.
It covers the following topics: Coding, Ood, Onsite, Phone .
More Affirm Interview Questions
1p3a
affirm fulltime software engineer tech phone screen interview overview
InterviewDB
Decision Tree - Implement Predict Traversal for a Binary Classification Tree
1p3a
Affirm Full-Time Tech Phone Screen Interview Experience
InterviewDB
Dispute Status - State Machine for Payment Dispute Lifecycle
InterviewDB
DOM Tree Manipulation - Build and Query a Simplified HTML DOM