Implement a deterministic Go Fish card game simulation
Company: Chime
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: easy
Interview Round: Other
Implement a simplified, fully deterministic version of the card game Go Fish. It simulates a multiplayer game in which players try to collect books (all four cards of one rank), and the player with the most books wins.
Nothing is random:
- The deck is created in a fixed order with no shuffling. Suits are ordered `["hearts", "diamonds", "clubs", "spades"]` and ranks `["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]`, so the deck starts as A of hearts, 2 of hearts, ..., K of hearts, A of diamonds, ..., K of spades.
- Dealing and drawing always take from the top of the deck (the front of the list).
- On each turn, the current player always asks the next player in seating order (index + 1, modulo the number of players).
- The rank requested is always the lowest rank in the current player's hand, using the rank order above (A lowest, K highest).
The game supports these operations:
- `Game(player_names: List[str])` creates the game and raises an error unless there are 2 to 6 players. Each player, in seating order, takes the next block of cards from the top of the deck: 7 cards each with 2 or 3 players, 5 cards each with 4 to 6 players. The first player in the list takes the first turn.
- `play_turn()` plays one turn of the game loop. Let `current` be the player whose turn it is and `opponent` the next player.
- If `current` has no cards, the turn passes to the next player.
- Otherwise let `rank` be the lowest rank in `current`'s hand. If `opponent` holds any cards of `rank`, all of them move to `current`, books are checked, and `current` takes another turn.
- If `opponent` has none, `current` draws the top card of the deck (if there is one), adds it to the hand and checks books. If the drawn card has the requested rank, `current` keeps the turn. In every other case, including an empty deck, the turn passes to the next player.
- A book is completed when a player holds all 4 cards of a rank. Those 4 cards leave the hand and the player's book count goes up by 1. Books are also checked after the initial deal.
- `is_over() -> bool` returns true when the deck is empty and every player's hand is empty.
- `get_winner() -> Player` returns the player with the most books. A tie goes to the earliest of the tied players in seating order.
- `start() -> str` runs turns until `is_over()` is true, then returns the winner's name.
Example:
```text
Input:
["Game", "start"]
[["Alice", "Bob", "Beth"], []]
Output:
[null, "Beth"]
```
`Game(["Alice", "Bob", "Beth"])` sets up a three-player game with the fixed deck, so each player is dealt 7 cards. `start()` plays the game to the end and returns `"Beth"`. The names never affect play, so the outcome depends only on the number of players.
```hint Rank order
Compare ranks by their position in the rank list. Before relying on a plain sort of the rank strings, check where it puts "10", "A" and the face cards.
```
### Constraints & Assumptions
- `2 <= number of players <= 6`
- Player names are non-empty ASCII strings.
- No shuffling, the asked player is always the next one in seating order, and the requested rank is always the lowest rank in hand.
- Up to `10^5` total method calls across all test cases.
### Clarifying Questions to Ask
- What should happen if the deck is empty and a whole round passes with no cards changing hands?
- Should tests be able to step through single turns and inspect hands, or is `start()` the only entry point?
- Can player names repeat, and does anything besides the returned winner depend on them?
- Should the classes leave room for a shuffled deck or player-chosen asks later, for example in a real game mode?
### What a Strong Answer Covers
- A class breakdown (card, deck, player, game) with clear ownership of hands, books and turn order.
- Rank selection that follows the A to K order from the rules.
- The turn logic: when the player keeps the turn, when it passes, and book detection after every change to a hand.
- The end condition, the tie-break, and why the game loop is guaranteed to finish (or what happens when it cannot).
- The time and space cost of a turn and of a full game.
### Follow-up Questions
- How would you let the current player choose any opponent and any rank they hold, as in the real game, while keeping tests deterministic?
- How would you add a seeded shuffle without breaking the existing deterministic tests?
- How would you record a log of every turn so a finished game can be replayed and checked?
- What changes if each player takes turns from a separate client connected to a server?
Overview: Implement a deterministic Go Fish card game for 2 to 6 players with a fixed deck order, fixed asking rules and book detection, then run it to the end and report the winner. It tests object-oriented design, following detailed rules exactly, turn control and making sure a simulation loop terminates.