Skip to content

fix: Fix index out of bounds in shanten table when encoding 14-tile hands - #178

Merged
smly merged 6 commits into
mainfrom
fix/validate-feature-encoding
Mar 14, 2026
Merged

fix: Fix index out of bounds in shanten table when encoding 14-tile hands#178
smly merged 6 commits into
mainfrom
fix/validate-feature-encoding

Conversation

@smly

@smly smly commented Mar 14, 2026

Copy link
Copy Markdown
Owner
  • Fix a panic (index out of bounds: the len is 15 but the index is 15) in hash_shupai when encode_shanten_efficiency / encode_extended is called during tsumo phase (14-tile hand)
  • Add calculate_effective_tiles_auto / calculate_effective_tiles_3p_auto that correctly handle both 13-tile (3n+1) and 14-tile (3n+2) hands

@smly smly self-assigned this Mar 14, 2026
@smly smly added bug Something isn't working core labels Mar 14, 2026
@smly
smly marked this pull request as ready for review March 14, 2026 15:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a panic in shanten/efficiency feature encoding when the encoder is invoked during the tsumo phase (14-tile hands), and adds tooling/docs to validate and describe the feature outputs.

Changes:

  • Add calculate_effective_tiles_auto / calculate_effective_tiles_3p_auto and route shanten-efficiency encoding through them to avoid 15-tile shanten evaluations.
  • Normalize replay Ankan actions’ consumed tiles to a canonical 4-tile set.
  • Expand Python stub docstrings with explicit shapes/dtypes and add a Tenhou log validation script.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/riichienv/_riichienv.pyi Adds detailed docstrings for observation encoders (shapes/dtypes/examples).
scripts/validate_tenhou_logs.py New end-to-end replay/encoding validator for Tenhou logs (4P/3P).
riichienv-core/src/shanten.rs Adds auto effective-tile helpers and asserts to prevent invalid hand sizes.
riichienv-core/src/replay/mod.rs Canonicalizes Ankan consumed tiles in replay step iterator (4P/3P).
riichienv-core/src/observation_3p/python.rs Switches shanten-efficiency effective-tile calc to the new 3P auto helper.
riichienv-core/src/observation_3p/encode.rs Switches shanten-efficiency effective-tile calc to the new 3P auto helper.
riichienv-core/src/observation/python.rs Switches shanten-efficiency effective-tile calc to the new auto helper.
riichienv-core/src/observation/encode.rs Switches shanten-efficiency effective-tile calc to the new auto helper.

💡 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.

Comment thread riichienv-core/src/shanten.rs Outdated
Comment thread riichienv-core/src/shanten.rs
Comment thread scripts/validate_tenhou_logs.py Outdated
Comment thread riichienv-core/src/shanten.rs Outdated
@smly
smly merged commit 9783454 into main Mar 14, 2026
7 checks passed
@smly
smly deleted the fix/validate-feature-encoding branch March 14, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants