Design a High-Card Game with a Persistent Tie Pot
AffirmSoftware Engineer · Technical ScreenLast updated
Design a high-card game in which tied rounds carry a persistent pot into later rounds, first for two players and then for many. Define card ownership, tie and exhaustion policies, deterministic shuffling, termination rules, extensible classes, and tests for tricky state transitions.
Design a High-Card Game with a Persistent Tie Pot
Model and implement a card game. A shuffled deck is split evenly among two players. In each round, every active player reveals the top card of their personal deck. A unique highest rank wins all cards currently in the pot. If the highest rank is tied, the revealed cards remain in the pot and another round is played. Begin with two players, then explain how the model and round logic extend to N players.
Focus on classes, ownership of cards, deterministic testing, tie handling, and termination. State a policy for players who cannot contribute a card while a tie pot is unresolved; pseudocode is acceptable.
Constraints & Assumptions
- Suits do not affect comparison; ranks have a total order.
- A card is in exactly one place: draw pile, current reveal, pot, or won pile.
- Shuffling is injected or seeded for deterministic tests.
- Because repeated play can cycle under some collection policies, define a maximum-round or repeated-state rule.
Clarifying Questions to Ask
- Does a winner place captured cards in a separate score pile or back into a draw pile?
- When only some players tie for highest rank, do all players enter the next tie-breaking round?
- What happens if a tied player runs out of cards?
- Is the winner determined by captured-card count, last active player, or another condition?
Follow-up questions
- How would you serialize and resume a game in progress?
- Which rule changes should require a new class rather than a conditional?
- How do you prove no card is lost or duplicated?
- What changes if captured cards return to the player's draw pile?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.