MahjongRepository / mahjong

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

[question] Are there detail options for Aka Dora ? #42

Closed muchojp closed 2 years ago

muchojp commented 2 years ago

Thank you for developing the mahjong package.

I have one question. Are there detailed options for Aka Dora? Using the example script, I tried the below script

tiles = TilesConverter.string_to_136_array(man='234555', pin='555', sou='22555')

win_tile = TilesConverter.string_to_136_array(sou='5')[0]

melds = None

dora_indicators = None

config = HandConfig(is_tsumo=True,is_rinshan=True, options=OptionalRules(has_open_tanyao=True, has_aka_dora=True))

result = calculator.estimate_hand_value(tiles, win_tile, melds, dora_indicators, config)
print_hand_result(result)

The result is

10 40
8000 4000
[Menzen Tsumo, Rinshan Kaihou, Tanyao, San Ankou, Sanshoku Doukou, Aka Dora 3]
{'fu': 20, 'reason': 'base'}
{'fu': 4, 'reason': 'closed_pon'}
{'fu': 4, 'reason': 'closed_pon'}
{'fu': 4, 'reason': 'closed_pon'}
{'fu': 2, 'reason': 'tsumo'}

With this config, three types (man, pin, and sou) of 5 are regarded as Aka. Thus, the result returns Aka Dora 3. If I want to specify man and pin include Aka Dora and sou isn't included Aka Dora, are there any options?

Best regards.

Nihisil commented 2 years ago

If I want to specify man and pin include Aka Dora and sou isn't included Aka Dora, are there any options?

You can try this one:

tiles = TilesConverter.string_to_136_array(man='234550', pin='550', sou='22555', has_aka_dora=True)

Where is 0 is aka dora. Also for aka doras you can use special constants (they are equal to tenhou.net aka dora tile codes): https://github.com/MahjongRepository/mahjong/blob/959d22b222bacfd773a4df10fc79120fe889a17f/mahjong/constants.py#L16

muchojp commented 2 years ago

Wow, It works! Thanks for replying and for the solution.

For visitors of this question, I'll make a note. I change the above script from

win_tile = TilesConverter.string_to_136_array(sou='5')[0]

into

win_tile = TilesConverter.string_to_136_array(sou='5', has_aka_dora=True)[0]

The reason: In the No Aka rule: man 5 -> 16-19 In the Aka rule: man red 5 -> 16, normal man 5 -> 17-19 The index is different a little bit between the rules.

Therefore, in the above case, we need to specify the win_tile is normal sou 5 (the index is different from Aka sou 5). If you forget has_aka_dora=True, the result will return None because the program considers win_tile is not included in tiles.