fix: restrict riichi_stage discards to tenpai-maintaining tiles#202
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a riichi state-machine bug where a Riichi action with tile = None (e.g. mjai reach) could be followed by a discard that breaks tenpai, by tightening legal-action generation and aligning handler-side preconditions.
Changes:
- Reworks 4P/3P
legal_actionsdiscard/riichi logic into explicit cases forriichi_declaredvsriichi_stage, restrictingriichi_stagediscards to tenpai-maintaining tiles. - Adds
!riichi_stageto theActionType::Riichihandler guards in both 4P/3P to prevent double-riichi while mid-declaration. - Adds a regression test and documents
riichi_declared/riichi_stageinvariants on player state structs.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| riichienv-core/src/tests.rs | Adds regression test ensuring riichi_stage only offers tenpai-maintaining discards and does not re-offer Riichi. |
| riichienv-core/src/state/legal_actions.rs | Implements three-case discard/riichi branching; enforces tenpai-maintaining discards during riichi_stage and tsumogiri-only after riichi_declared. |
| riichienv-core/src/state/mod.rs | Adds !riichi_stage precondition to the Riichi action handler to prevent re-entrant riichi declarations. |
| riichienv-core/src/state/player.rs | Documents riichi_declared/riichi_stage meaning and constraints for 4P player state. |
| riichienv-core/src/state_3p/legal_actions.rs | Mirrors the 4P legal-actions rewrite for 3P using HandEvaluator3P::is_tenpai. |
| riichienv-core/src/state_3p/mod.rs | Adds !riichi_stage guard to the 3P Riichi action handler. |
| riichienv-core/src/state_3p/player.rs | Documents riichi_declared/riichi_stage meaning and constraints for 3P player state. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Fixes #196.
The original report attached a game log (
game_0033_seed_50.zip, East 2nd / step 260) where this manifested as a riichi declared on a hand whose shape was no longer tenpai.Fix
declaration_turnand rewrite the discard / riichi branch instate/legal_actions.rsandstate_3p/legal_actions.rsinto three explicit cases on the two flags:riichi_declared→ tsumogiri only.riichi_stage→ only discards that keep the hand tenpai, checked viaHandEvaluator::is_tenpai(HandEvaluator3Pfor 3P).forbidden_discardsis still respected.Riichioption when the eligibility conditions are met.!riichi_stageto the inner check of theActionType::Riichibranch instate/mod.rsandstate_3p/mod.rsso the handler's precondition matches the legal-actions guard, even on paths that bypassstep()validation.riichi_declaredandriichi_stageonPlayerStateandPlayerState3Pdescribing the mutual exclusion and the legal-action restrictions that must hold whileriichi_stageis set.