MahjongRepository/mahjong

hand_not_winning for pons containing dragons

Varantha opened this issue · 2 comments

Hi there,

I think there's an issue with hands that contain pons of dragon tiles.

I've ran the below, unless I'm wrong 777h is a pon of chun tiles so the hand should be winning with at least 1 yaku.

I've tested and get the same for 666h and 555h seems to give a terminating error.

Is this a bug or am I doing something wrong?

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("678s678p55m")
win_tile =TilesConverter.one_line_string_to_136_array("8s")[0]

melds = [
    Meld(meld_type="pon", tiles=TilesConverter.one_line_string_to_136_array("777h"), opened=True),
    Meld(meld_type="chi", tiles=TilesConverter.one_line_string_to_136_array("234p"), opened=True)
    ]

result = calculator.estimate_hand_value(tiles, win_tile,melds)

print(result)

For dragons please use z, not h.

Working example:

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("678s234678p55m777z")
win_tile = TilesConverter.one_line_string_to_136_array("8s")[0]

melds = [
    Meld(meld_type="pon", tiles=TilesConverter.one_line_string_to_136_array("777z"), opened=True),
    Meld(meld_type="chi", tiles=TilesConverter.one_line_string_to_136_array("234p"), opened=True)
]

result = calculator.estimate_hand_value(tiles, win_tile, melds)

print(result)

You can see more examples of library usage in tests: https://github.com/MahjongRepository/mahjong/blob/master/mahjong/hand_calculating/tests/tests_yaku_calculation.py

Ah.
I realise my issue, I didn't realise "tiles" needed to contain the Meld tiles. I assume it was "tiles in hand that aren't melds".

I've tested adding the dragons into the hand (with both h and z) and it works now.

Thanks for the quick response!