MahjongRepository / mahjong

Implementation of riichi mahjong related stuff (hand cost, shanten, agari end, etc.)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enhancement: Add one line string to 136/34 array

illava opened this issue · comments

Enhancement: Add one line string to 136/34 array in file tile.py.

    @staticmethod
    def one_line_string_to_136_array(string=None, has_aka_dora=False):
        """
        Method to convert one line string tiles format to the 136 array, like
        "123s456p789m11222z". 's' stands for sou, 'p' stands for pin, 
        'm' stands for man and 'z' or 'h' stands for honor.
        You can pass r or 0 instead of 5 for it to become a red five from
        that suit. To prevent old usage without red,
        has_aka_dora has to be True for this to do that.
        We need it to increase readability of our tests
        """
        sou = ""
        pin = ""
        man = ""
        honors = ""
		
        split_start = 0
		
        for index, i in enumerate(string):
            if i == 'm':
                man += string[split_start: index]
                split_start = index + 1
            if i == 'p':
                pin += string[split_start: index]
                split_start = index + 1
            if i == 's':
                sou += string[split_start: index]
                split_start = index + 1
            if i == 'z' or i == 'h':
                honors += string[split_start: index]
                split_start = index + 1
				
        return TilesConverter.string_to_136_array(sou, pin, man, honors, has_aka_dora)
    @staticmethod
    def one_line_string_to_34_array(string=None):
        """
        Method to convert one line string tiles format to the 34 array
        We need it to increase readability of our tests
        """
        results = TilesConverter.one_line_string_to_136_array(string)
        results = TilesConverter.to_34_array(results)
        return results
>>> import tile
>>> tile.TilesConverter.one_line_string_to_34_array("555s456p789m11222z")
[0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0]
>>> tile.TilesConverter.one_line_string_to_136_array("555s456p789m11222z", has_aka_dora = True)
[24, 28, 32, 48, 53, 56, 89, 90, 91, 108, 109, 112, 113, 114]

Sincerely Illava.

@illava Thanks! It was added to released 1.1.9 version