MahjongRepository / mahjong

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

Aka Dora han not calculated #14

Closed illava closed 5 years ago

illava commented 5 years ago

I'm trying the examples of the project while aka dora is not calculated in hand calculator. Was it somewhere wrong configed?

Code

from mahjong.hand_calculating.hand import HandCalculator
from mahjong.meld import Meld
from mahjong.hand_calculating.hand_config import HandConfig, OptionalRules
from mahjong.shanten import Shanten
from mahjong.tile import TilesConverter

calculator = HandCalculator()

# useful helper
def print_hand_result(hand_result):
    print(hand_result.han, hand_result.fu)
    print(hand_result.cost['main'])
    print(hand_result.yaku)
    for fu_item in hand_result.fu_details:
        print(fu_item)
    print('')

tiles = TilesConverter.string_to_136_array(man='22444', pin='333r67', sou='444', has_aka_dora = True)
win_tile = TilesConverter.string_to_136_array(sou='4')[0]
handconfig = HandConfig()
handconfig.has_aka_dora = True
handconfig.is_daburu_riichi = True
result = calculator.estimate_hand_value(tiles, win_tile, config = handconfig)
print_hand_result(result)

Expected

4 40
8000
[Double Riichi, Tanyao, Aka Dora 1]
{'fu': 30, 'reason': 'base'}
{'fu': 4, 'reason': 'closed_pon'}
{'fu': 4, 'reason': 'closed_pon'}
{'fu': 2, 'reason': 'open_pon'}

Actural

3 40
5200
[Double Riichi, Tanyao]
{'fu': 30, 'reason': 'base'}
{'fu': 4, 'reason': 'closed_pon'}
{'fu': 4, 'reason': 'closed_pon'}
{'fu': 2, 'reason': 'open_pon'}

ver.1.1.7 python3 PS. Aka Dora usually express as "0" in games like tenhou, 11223s4506p3405s2z etc. It'll be nice if "r" and "0" are both representing aka dora. Sincerely Illava.

Nihisil commented 5 years ago

@illava has_aka_dora=True had to be set to the options, not to the config itself.

from mahjong.hand_calculating.hand import HandCalculator
from mahjong.hand_calculating.hand_config import HandConfig, OptionalRules
from mahjong.tile import TilesConverter

calculator = HandCalculator()

def print_hand_result(hand_result):
    print(hand_result.han, hand_result.fu)
    print(hand_result.cost['main'])
    print(hand_result.yaku)
    for fu_item in hand_result.fu_details:
        print(fu_item)
    print('')

tiles = TilesConverter.string_to_136_array(man='22444', pin='333r67', sou='444', has_aka_dora=True)
win_tile = TilesConverter.string_to_136_array(sou='4')[0]
hand_config = HandConfig(
    is_daburu_riichi=True,
    options=OptionalRules(has_aka_dora=True),
)
result = calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
print_hand_result(result)

Also, with v1.1.8 version you can pass 0 instead of r as aka dora to tiles converter: https://github.com/MahjongRepository/mahjong/releases/tag/v1.1.8