fix(3p): correct dead wall layout and rinshan draw logic (#183)#186
Merged
fix(3p): correct dead wall layout and rinshan draw logic (#183)#186
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a 3P (sanma) wall-layout bug where rinshan draws could consume dora indicator tiles (leading to an indicator tile type appearing “5 times”), and refactors wall exhaustion logic in both 3P and 4P to use an explicit drawable_count rather than tiles.len() magic-number checks.
Changes:
- 3P: Adjust wall layout / rinshan draw path to prevent consuming dora/ura indicator tiles; add regression tests in
WallState3P. - 3P + 4P: Introduce and plumb
drawable_countthrough draw/exhaustion/riichi/haitei/houtei logic and replay event handling. - Tests + replay init: Update unit tests and replay initialization to keep
drawable_countin sync (fixing the reported off-by-one legality issue).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
riichienv-core/src/state_3p/wall.rs |
Reworks 3P indicator indexing and adds draw_rinshan_tile() plus regression tests for issue #183. |
riichienv-core/src/state_3p/sanma.rs |
Switches kita legality and rinshan draw to use drawable_count and draw_rinshan_tile(). |
riichienv-core/src/state_3p/mod.rs |
Updates 3P riichi/haitei/houtei/kan draw/deal flow to use drawable_count; initializes the counter per-round. |
riichienv-core/src/state_3p/legal_actions.rs |
Aligns 3P legal-action gates (riichi/kan/haitei/houtei/pon/kan) with drawable_count. |
riichienv-core/src/state_3p/event_handler.rs |
Keeps replay-driven wall consumption consistent by decrementing drawable_count when popping wall tiles. |
riichienv-core/src/state/wall.rs |
Adds drawable_count to the 4P wall state and resets it on shuffle/load. |
riichienv-core/src/state/mod.rs |
Refactors 4P riichi/haitei/houtei/kan draw/deal flow to use drawable_count; initializes the counter per-round. |
riichienv-core/src/state/legal_actions.rs |
Aligns 4P legal-action gates (riichi/kan/chi/haitei/houtei/pon/kan) with drawable_count. |
riichienv-core/src/state/event_handler.rs |
Keeps replay-driven wall consumption consistent by decrementing drawable_count when popping wall tiles. |
riichienv-core/src/replay/mod.rs |
Fixes replay initialization accounting by incrementing drawable_count when pushing back the oya draw tile. |
riichienv-core/src/replay/mjai_replay.rs |
Updates documentation comment to match the “non-drawable reserve” concept. |
riichienv-core/src/tests.rs |
Updates sanma unit tests to set drawable_count after overriding the wall tiles. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
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 a bug where dora indicator tiles could be consumed by rinshan draws in 3P mode, causing a tile type to appear more than 4 times (#183). Plus,
drawable_countcounter instead of comparingtiles.len()against a magic numberRoot cause
In 3P mahjong, both kan and kita (north extraction) draw rinshan tiles from the dead wall. The old implementation allocated only 4 rinshan slots (same as 4P), but 3P requires 8 (4 kan + 4 kita). After the 4th rinshan draw,
tiles.remove(0)consumed dora indicator tiles, making them appear both on the dead wall and in a player's hand.Validation
validate_logs.py3P: 5000/5000 passedvalidate_logs.py4P: 5000/5000 passedCloses #183