Skip to content

fix(game): form book on non-matching draw#5

Merged
folkengine merged 1 commit into
mainfrom
bookem
May 12, 2026
Merged

fix(game): form book on non-matching draw#5
folkengine merged 1 commit into
mainfrom
bookem

Conversation

@folkengine
Copy link
Copy Markdown
Contributor

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:

  • 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

  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
@folkengine folkengine merged commit 5d6f5e3 into main May 12, 2026
18 checks passed
@folkengine folkengine deleted the bookem branch May 12, 2026 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant