mahjong
mahjong copied to clipboard
[Bug] `ValueError: negative shift count` at calculating hand.(Test code included)
Description:
I encountered a potential issue with the tile reduction logic used in the hand calculation process. The current implementation seems to decrement the tile count incorrectly, which might lead to a ValueError
. I've provided a test code snippet and a link to the relevant code section for your review.
Test Code:
from mahjong.meld import Meld
from mahjong.tile import TilesConverter
from mahjong.hand_calculating.hand import HandCalculator
# Setup melds and tiles
melds = [
Meld(meld_type=Meld.CHI, tiles=TilesConverter.string_to_136_array(sou="678")),
Meld(meld_type=Meld.CHI, tiles=TilesConverter.string_to_136_array(man="345")),
Meld(meld_type=Meld.CHI, tiles=TilesConverter.string_to_136_array(pin="345")),
Meld(meld_type=Meld.PON, tiles=TilesConverter.string_to_136_array(honors="222"))
]
tiles = TilesConverter.string_to_136_array(sou='33')
win_tile = TilesConverter.string_to_136_array(sou='3')[0]
# Calculate hand value
calculator = HandCalculator()
result = calculator.estimate_hand_value(tiles=tiles, melds=melds, win_tile=win_tile)
Suspected Issue:
I suspect there might be an issue with the tiles[x] -= x
logic in the code, as it seems leading to <<
a negative number.
Relevant Code Section: https://github.com/MahjongRepository/mahjong/blob/cb749aa6f7087470c91a162628399b9565d8f235/mahjong/agari.py#L17-L41
Expected vs. Actual Results:
For reference, here's the result from Tenhou:
BTW I dont find any test case for this in this repo.