Fix MJAI replay start_kyoku wall initialization - #162
Merged
Conversation
hong0311
marked this pull request as ready for review
March 10, 2026 09:08
smly
self-requested a review
March 10, 2026 09:35
Owner
|
@hong0311 Thanks for the PR! This looks like a solid and important bug fix for the MJAI replay. Really appreciate it! I'll verify the repro using the paifu mentioned in the description just to be safe. P.S. Now I remember — I originally implemented replay for mjsoul logs first, and added MJAI log replay later. In mjsoul logs, the dealer receives 14 tiles in the start_kyoku equivalent. That's exactly where this off-by-one came from... |
smly
approved these changes
Mar 10, 2026
| self.is_after_kan = false; | ||
| self.riichi_sutehais = [None; 4]; | ||
| self.last_tedashis = [None; 4]; | ||
| self.wall.tiles = vec![0; 136 - 13 * 4]; |
Owner
There was a problem hiding this comment.
Just to note: the minimal fix for the off-by-one is self.wall.tiles = vec![0; 136 - 13 * 4] (and the corresponding line for 3p). The rest are preventive resets and regression tests, which are welcome.
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.
Summary
Fix an off-by-one bug in MJAI replay initialization.
apply_mjai_event(start_kyoku)was leaving replay state in the post-dealer-draw position, even though MJAI logs emit the dealer's first draw as a separatetsumoevent. When that loggedtsumowas applied, the wall became one tile too short for the rest of the round.This mostly goes unnoticed, but it breaks legality checks near the end of the hand where rules depend on the remaining wall count. In the reproduced case, a real
chiwindow was reconstructed asRon/Pass, andselect_action_from_mjai(...)failed to resolve the source event.What changed
start_kyokustart_kyokuso replay starts from a clean round stateWhy this fixes the bug
For MJAI replay, the correct sequence is:
start_kyoku-> wall is still pre-dealer-drawtsumo-> consume exactly one tileBefore this patch, replay effectively started one step too late, so the first logged
tsumoconsumed an extra tile and shifted the rest of the round out of sync.Repro
Using
2024010109gm-00a9-0000-1fe4306c.json:9s, seat 3 sawRon/PassChi/Passselect_action_from_mjai({"type":"chi","actor":3,"target":2,"pai":"9s","consumed":["7s","8s"]})now resolves successfullyTesting
cargo test -q apply_mjai_event_start_kyoku -- --nocapturecargo test -q test_apply_mjai_event_honor_and_red_tiles -- --nocaptureManual verification:
apply_mjai_event(...)chi