MahjongRepository / mahjong

Implementation of riichi mahjong related stuff (hand cost, shanten, agari end, etc.)
MIT License
377 stars 38 forks source link

Another fu calculation error #41

Closed joeygannon closed 3 years ago

joeygannon commented 3 years ago

This seems similar to #40, but I'm not sure if it's actually a duplicate. In this case it impacts the reported cost:

from mahjong.hand_calculating.hand import HandCalculator
from mahjong.tile import TilesConverter
from mahjong.hand_calculating.hand_config import HandConfig
from mahjong.meld import Meld

calculator = HandCalculator()
tiles = TilesConverter.one_line_string_to_136_array('11112233444m555p')
melds = [Meld(meld_type=Meld.CHI, tiles=TilesConverter.string_to_136_array(man='123'))]
win_tile = TilesConverter.one_line_string_to_136_array('1m')[0]

result = calculator.estimate_hand_value(tiles, win_tile, melds=melds, config=HandConfig(is_houtei=True))

print(result.han, result.fu)
print(result.cost['main'])
print(result.yaku)
for fu_item in result.fu_details:
    print(fu_item)
1 40
1300
[Houtei Raoyui]
{'fu': 20, 'reason': 'base'}
{'fu': 8, 'reason': 'closed_terminal_pon'}
{'fu': 4, 'reason': 'closed_pon'}

There can't be a closed_terminal_pon here because one of the 1m is in a chi and another is called for ron. Either open_terminal_pon (if you treat it as shanpon and divide it 111 234 44 555) or closed_pon (treat it as ryanmen and divide it 11 123 444 555) would be correct, and either reduces the fu to 30.

Nihisil commented 3 years ago

Thanks for the report. It was a tricky bug. The fix is available in the pre-release version: https://pypi.org/project/mahjong/1.2.0.dev6/

1.2.0.dev is different from the 1.1 version, there could be issues with migration.

I plan to finish the localization system in the next months and will release the 1.2.0 version with a migration guide together.

joeygannon commented 3 years ago

That's a tricky one indeed. Thank you for the quick fix!