fix(game): form book on non-matching draw#5
Merged
Merged
Conversation
handle_draw only checked for a completed book when the drawn card matched
the asked rank. A non-matching draw can still complete a book of the drawn
card's rank, leaving the player stuck holding all four cards for the rest
of the game. Fix by checking the drawn card's rank in both branches.
Summary
The defect is in gfcore, not gfarena. gfarena's src/lib.rs is just a WASM shim re-exporting gfcore::wasm_api.
Root cause: Game::handle_draw in src/game/state.rs only checked for a completed book when the drawn card matched the asked rank. A non-matching draw can
still complete a book of the drawn card's own rank (player held three of X, asked for Y, drew the fourth X).
Evidence in the recorded game: Player 0 ("You") held 4♦, 4♣ from the deal, picked up 4♥ from Lucky on turn 9, then on turn 17 asked Lucky for a 9 → Go Fish
→ drew 4♠ from the pile. All four 4s were in hand but books_after_turn stayed at [1,0,0,0], and P0 wasted turns 25 and 33 asking for 4s that no one else
could possibly have.
Fix: Capture the drawn card's rank and always pass it to check_and_collect_book regardless of matched. When matched is true and a book forms, the player
goes again (BookCompleted); when matched is false, the turn still advances (preserves the standard "no match ends turn" rule) but the book is recorded.
Files changed:
- src/game/state.rs — Game::handle_draw rewritten around the draw/book branch
- src/game/state.rs — added test_handle_draw_forms_book_on_non_matching_draw regression test next to the existing matched: false test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(game): form book on non-matching drawhandle_draw only checked for a completed book when the drawn card matched the asked rank. A non-matching draw can still complete a book of the drawn card's rank, leaving the player stuck holding all four cards for the rest of the game. Fix by checking the drawn card's rank in both branches.
Summary
The defect is in gfcore, not gfarena. gfarena's src/lib.rs is just a WASM shim re-exporting gfcore::wasm_api.
Root cause: Game::handle_draw in src/game/state.rs only checked for a completed book when the drawn card matched the asked rank. A non-matching draw can
still complete a book of the drawn card's own rank (player held three of X, asked for Y, drew the fourth X).
Evidence in the recorded game: Player 0 ("You") held 4♦, 4♣ from the deal, picked up 4♥ from Lucky on turn 9, then on turn 17 asked Lucky for a 9 → Go Fish
→ drew 4♠ from the pile. All four 4s were in hand but books_after_turn stayed at [1,0,0,0], and P0 wasted turns 25 and 33 asking for 4s that no one else
could possibly have.
Fix: Capture the drawn card's rank and always pass it to check_and_collect_book regardless of matched. When matched is true and a book forms, the player
goes again (BookCompleted); when matched is false, the turn still advances (preserves the standard "no match ends turn" rule) but the book is recorded.
Files changed: