MahjongRepository / mahjong

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

Enhancement:Print red dora in one_line_string #17

Closed illava closed 4 years ago

illava commented 5 years ago

I'm dealing with tiles with red dora and these might be useful debugging. In tile.py. Sincerely Illava

    @staticmethod
    def to_one_line_string(tiles, has_aka_dora=False):
        """
        Convert 136 tiles array to the one line string
        Example of output 123s123p123m33z
        """
        tiles = sorted(tiles)

        man = [t for t in tiles if t < 36]

        pin = [t for t in tiles if 36 <= t < 72]
        pin = [t - 36 for t in pin]

        sou = [t for t in tiles if 72 <= t < 108]
        sou = [t - 72 for t in sou]

        honors = [t for t in tiles if t >= 108]
        honors = [t - 108 for t in honors]

        def words(suits, red_five, suffix):
            return suits and ''.join(["0" if i == red_five and has_aka_dora else str((i // 4) + 1) for i in suits]) + suffix or ''    

        sou = words(sou, FIVE_RED_SOU - 72, 's')
        pin = words(pin, FIVE_RED_PIN - 36, 'p')
        man = words(man, FIVE_RED_MAN, 'm')
        honors = words(honors, -1 - 108, 'z')

        return man + pin + sou + honors
>>> import tile
>>> tile.TilesConverter.to_one_line_string([1,16,13,46,5,13,24,34,134,124])
'1244579m3p57z'
>>> tile.TilesConverter.to_one_line_string([1,16,13,46,5,13,24,34,134,124], False)
'1244579m3p57z'
>>> tile.TilesConverter.to_one_line_string([1,16,13,46,5,13,24,34,134,124], True)
'1244079m3p57z'
Nihisil commented 4 years ago

Was implemented here: https://github.com/MahjongRepository/mahjong/commit/b9cb31c16f11a24471e072c05138e66a8ff0a8a9