You are given a simplified card game engine with unit tests. The game is played using a table of face-up cards; each card has an integer value.
On each turn, a player draws exactly 3 cards from the table (removing them from the table). A turn scores 1 point if the three drawn card values sum to 15; otherwise it scores 0. The game ends when fewer than 3 cards remain.
Part 1 — Debugging
A unit test fails because the current draw_three_cards() (or equivalent) method sometimes returns cards that were not present on the table at the moment of drawing.
Task: Fix the draw method so that all three cards are always selected from the current table state, and the selected cards are removed from the table.
Part 2 — Implement a naive strategy
Implement a simple baseline strategy for selecting three cards each turn.
Example of an acceptable baseline:
-
Repeatedly choose
any
triple of currently available cards whose values sum to 15 (if such a triple exists); otherwise draw any three cards.
Part 3 — Measure strategy quality by simulation
Define a way to evaluate a strategy by simulation:
-
Simulate many random initial deals / shuffles.
-
Compute the fraction of games where the strategy achieves a “perfect score” (i.e., scores 1 on every possible turn), and/or compute average total score.
Task: Implement the evaluation harness and report the metric(s).
Part 4 — Improve the strategy
Improve the strategy to maximize total score.
Task: Implement an optimized strategy (e.g., search/backtracking over possible sequences of draws) that attempts to maximize total points over the whole game.
What to clarify during the interview
If not already specified in the provided code/tests, state reasonable assumptions for:
-
How the initial table is generated (deck composition, table size).
-
Whether card values can repeat.
-
Determinism vs randomness in drawing.
-
What constitutes a “perfect score” in the test harness.