from PIL import Image,ImageDraw,ImageFont
import os



class Hai:

    def __init__(self,zoku,value):

        basedir = os.path.abspath(os.path.dirname(__file__))

        self.japanese_zoku = {0:'字牌',1:'索子',2:'筒子',3:'萬子'}
        self.japanese_jihai_value = {0:'トン',1:'ナン',2:'シャー',3:'ペー',4:'ハク',5:'ハツ',6:'チュン'}
        self.japanese_value = {0:'イー',1:'リャン',2:'サン',3:'スー',4:'ウー',5:'ロー',6:'チー',7:'バー',8:'キュー'}
        self.japanese_zoku_yomi = {0:'',1:'ソウ',2:'ピン',3:'ワン'}

        #function to round corners of hai pics
        def pic_corner_round(img):
            rounded_rect = Image.new('L',img.size,'black')
            draw = ImageDraw.Draw(rounded_rect)
            draw.rounded_rectangle((0,0,img.size[0],img.size[1]),radius=20,fill='white')
            img.putalpha(rounded_rect)
            return img
        self.pic = pic_corner_round(Image.open(basedir + '/static/'+'{},{}.jpg'.format(zoku,value)))
        self.pic = self.pic.resize((60,100))
        #self.pic = pic_corner_round(self.pic)


        self.zoku = zoku

        #only accept up to 7 for jihai
        if self.zoku == 0:
            if value > 6:
                raise ValueError('Jihai value cannot be greater than 7')
            else:
                self.value = value
        #only accept value up to 8 for non jihai
        elif self.zoku != 0:
            if value > 8:
                raise ValueError('Non-jihai value cannot exceed 9')
            self.value = value

        self.id = (self.zoku,self.value)

    def __str__(self):
        #check if jihai or not
        if self.zoku == 0:
            return f'{self.japanese_zoku[self.zoku]}の{self.japanese_jihai_value[self.value]}'
        else:
            return f'{self.japanese_zoku[self.zoku]}の{self.value + 1}'

    def __getitem__(self,item):
        return self.id[item]

    def __lt__(self,other):
        return self.id < other.id

    def __gt__(self,other):
        return self.id > other.id

    def __eq__(self,other):
        if other == None:
            return False
        elif self.id == other.id:
            return True
        else:
            return False

    def __hash__(self):
        return id(self)

    def __iter__(self):
        yield from self.__values

d80f76bf73ef760a30f9a0b7a86869ef28a86db8
<mask token>


class Hai:

    def __init__(self, zoku, value):
        basedir = os.path.abspath(os.path.dirname(__file__))
        self.japanese_zoku = {(0): '字牌', (1): '索子', (2): '筒子', (3): '萬子'}
        self.japanese_jihai_value = {(0): 'トン', (1): 'ナン', (2): 'シャー', (3):
            'ペー', (4): 'ハク', (5): 'ハツ', (6): 'チュン'}
        self.japanese_value = {(0): 'イー', (1): 'リャン', (2): 'サン', (3): 'スー',
            (4): 'ウー', (5): 'ロー', (6): 'チー', (7): 'バー', (8): 'キュー'}
        self.japanese_zoku_yomi = {(0): '', (1): 'ソウ', (2): 'ピン', (3): 'ワン'}

        def pic_corner_round(img):
            rounded_rect = Image.new('L', img.size, 'black')
            draw = ImageDraw.Draw(rounded_rect)
            draw.rounded_rectangle((0, 0, img.size[0], img.size[1]), radius
                =20, fill='white')
            img.putalpha(rounded_rect)
            return img
        self.pic = pic_corner_round(Image.open(basedir + '/static/' +
            '{},{}.jpg'.format(zoku, value)))
        self.pic = self.pic.resize((60, 100))
        self.zoku = zoku
        if self.zoku == 0:
            if value > 6:
                raise ValueError('Jihai value cannot be greater than 7')
            else:
                self.value = value
        elif self.zoku != 0:
            if value > 8:
                raise ValueError('Non-jihai value cannot exceed 9')
            self.value = value
        self.id = self.zoku, self.value
    <mask token>

    def __getitem__(self, item):
        return self.id[item]

    def __lt__(self, other):
        return self.id < other.id
    <mask token>
    <mask token>

    def __hash__(self):
        return id(self)

    def __iter__(self):
        yield from self.__values

<mask token>


class Hai:

    def __init__(self, zoku, value):
        basedir = os.path.abspath(os.path.dirname(__file__))
        self.japanese_zoku = {(0): '字牌', (1): '索子', (2): '筒子', (3): '萬子'}
        self.japanese_jihai_value = {(0): 'トン', (1): 'ナン', (2): 'シャー', (3):
            'ペー', (4): 'ハク', (5): 'ハツ', (6): 'チュン'}
        self.japanese_value = {(0): 'イー', (1): 'リャン', (2): 'サン', (3): 'スー',
            (4): 'ウー', (5): 'ロー', (6): 'チー', (7): 'バー', (8): 'キュー'}
        self.japanese_zoku_yomi = {(0): '', (1): 'ソウ', (2): 'ピン', (3): 'ワン'}

        def pic_corner_round(img):
            rounded_rect = Image.new('L', img.size, 'black')
            draw = ImageDraw.Draw(rounded_rect)
            draw.rounded_rectangle((0, 0, img.size[0], img.size[1]), radius
                =20, fill='white')
            img.putalpha(rounded_rect)
            return img
        self.pic = pic_corner_round(Image.open(basedir + '/static/' +
            '{},{}.jpg'.format(zoku, value)))
        self.pic = self.pic.resize((60, 100))
        self.zoku = zoku
        if self.zoku == 0:
            if value > 6:
                raise ValueError('Jihai value cannot be greater than 7')
            else:
                self.value = value
        elif self.zoku != 0:
            if value > 8:
                raise ValueError('Non-jihai value cannot exceed 9')
            self.value = value
        self.id = self.zoku, self.value
    <mask token>

    def __getitem__(self, item):
        return self.id[item]

    def __lt__(self, other):
        return self.id < other.id

    def __gt__(self, other):
        return self.id > other.id

    def __eq__(self, other):
        if other == None:
            return False
        elif self.id == other.id:
            return True
        else:
            return False

    def __hash__(self):
        return id(self)

    def __iter__(self):
        yield from self.__values

<mask token>


class Hai:

    def __init__(self, zoku, value):
        basedir = os.path.abspath(os.path.dirname(__file__))
        self.japanese_zoku = {(0): '字牌', (1): '索子', (2): '筒子', (3): '萬子'}
        self.japanese_jihai_value = {(0): 'トン', (1): 'ナン', (2): 'シャー', (3):
            'ペー', (4): 'ハク', (5): 'ハツ', (6): 'チュン'}
        self.japanese_value = {(0): 'イー', (1): 'リャン', (2): 'サン', (3): 'スー',
            (4): 'ウー', (5): 'ロー', (6): 'チー', (7): 'バー', (8): 'キュー'}
        self.japanese_zoku_yomi = {(0): '', (1): 'ソウ', (2): 'ピン', (3): 'ワン'}

        def pic_corner_round(img):
            rounded_rect = Image.new('L', img.size, 'black')
            draw = ImageDraw.Draw(rounded_rect)
            draw.rounded_rectangle((0, 0, img.size[0], img.size[1]), radius
                =20, fill='white')
            img.putalpha(rounded_rect)
            return img
        self.pic = pic_corner_round(Image.open(basedir + '/static/' +
            '{},{}.jpg'.format(zoku, value)))
        self.pic = self.pic.resize((60, 100))
        self.zoku = zoku
        if self.zoku == 0:
            if value > 6:
                raise ValueError('Jihai value cannot be greater than 7')
            else:
                self.value = value
        elif self.zoku != 0:
            if value > 8:
                raise ValueError('Non-jihai value cannot exceed 9')
            self.value = value
        self.id = self.zoku, self.value

    def __str__(self):
        if self.zoku == 0:
            return (
                f'{self.japanese_zoku[self.zoku]}の{self.japanese_jihai_value[self.value]}'
                )
        else:
            return f'{self.japanese_zoku[self.zoku]}の{self.value + 1}'

    def __getitem__(self, item):
        return self.id[item]

    def __lt__(self, other):
        return self.id < other.id

    def __gt__(self, other):
        return self.id > other.id

    def __eq__(self, other):
        if other == None:
            return False
        elif self.id == other.id:
            return True
        else:
            return False

    def __hash__(self):
        return id(self)

    def __iter__(self):
        yield from self.__values

from PIL import Image, ImageDraw, ImageFont
import os


class Hai:

    def __init__(self, zoku, value):
        basedir = os.path.abspath(os.path.dirname(__file__))
        self.japanese_zoku = {(0): '字牌', (1): '索子', (2): '筒子', (3): '萬子'}
        self.japanese_jihai_value = {(0): 'トン', (1): 'ナン', (2): 'シャー', (3):
            'ペー', (4): 'ハク', (5): 'ハツ', (6): 'チュン'}
        self.japanese_value = {(0): 'イー', (1): 'リャン', (2): 'サン', (3): 'スー',
            (4): 'ウー', (5): 'ロー', (6): 'チー', (7): 'バー', (8): 'キュー'}
        self.japanese_zoku_yomi = {(0): '', (1): 'ソウ', (2): 'ピン', (3): 'ワン'}

        def pic_corner_round(img):
            rounded_rect = Image.new('L', img.size, 'black')
            draw = ImageDraw.Draw(rounded_rect)
            draw.rounded_rectangle((0, 0, img.size[0], img.size[1]), radius
                =20, fill='white')
            img.putalpha(rounded_rect)
            return img
        self.pic = pic_corner_round(Image.open(basedir + '/static/' +
            '{},{}.jpg'.format(zoku, value)))
        self.pic = self.pic.resize((60, 100))
        self.zoku = zoku
        if self.zoku == 0:
            if value > 6:
                raise ValueError('Jihai value cannot be greater than 7')
            else:
                self.value = value
        elif self.zoku != 0:
            if value > 8:
                raise ValueError('Non-jihai value cannot exceed 9')
            self.value = value
        self.id = self.zoku, self.value

    def __str__(self):
        if self.zoku == 0:
            return (
                f'{self.japanese_zoku[self.zoku]}の{self.japanese_jihai_value[self.value]}'
                )
        else:
            return f'{self.japanese_zoku[self.zoku]}の{self.value + 1}'

    def __getitem__(self, item):
        return self.id[item]

    def __lt__(self, other):
        return self.id < other.id

    def __gt__(self, other):
        return self.id > other.id

    def __eq__(self, other):
        if other == None:
            return False
        elif self.id == other.id:
            return True
        else:
            return False

    def __hash__(self):
        return id(self)

    def __iter__(self):
        yield from self.__values

from PIL import Image,ImageDraw,ImageFont
import os



class Hai:

    def __init__(self,zoku,value):

        basedir = os.path.abspath(os.path.dirname(__file__))

        self.japanese_zoku = {0:'字牌',1:'索子',2:'筒子',3:'萬子'}
        self.japanese_jihai_value = {0:'トン',1:'ナン',2:'シャー',3:'ペー',4:'ハク',5:'ハツ',6:'チュン'}
        self.japanese_value = {0:'イー',1:'リャン',2:'サン',3:'スー',4:'ウー',5:'ロー',6:'チー',7:'バー',8:'キュー'}
        self.japanese_zoku_yomi = {0:'',1:'ソウ',2:'ピン',3:'ワン'}

        #function to round corners of hai pics
        def pic_corner_round(img):
            rounded_rect = Image.new('L',img.size,'black')
            draw = ImageDraw.Draw(rounded_rect)
            draw.rounded_rectangle((0,0,img.size[0],img.size[1]),radius=20,fill='white')
            img.putalpha(rounded_rect)
            return img
        self.pic = pic_corner_round(Image.open(basedir + '/static/'+'{},{}.jpg'.format(zoku,value)))
        self.pic = self.pic.resize((60,100))
        #self.pic = pic_corner_round(self.pic)


        self.zoku = zoku

        #only accept up to 7 for jihai
        if self.zoku == 0:
            if value > 6:
                raise ValueError('Jihai value cannot be greater than 7')
            else:
                self.value = value
        #only accept value up to 8 for non jihai
        elif self.zoku != 0:
            if value > 8:
                raise ValueError('Non-jihai value cannot exceed 9')
            self.value = value

        self.id = (self.zoku,self.value)

    def __str__(self):
        #check if jihai or not
        if self.zoku == 0:
            return f'{self.japanese_zoku[self.zoku]}の{self.japanese_jihai_value[self.value]}'
        else:
            return f'{self.japanese_zoku[self.zoku]}の{self.value + 1}'

    def __getitem__(self,item):
        return self.id[item]

    def __lt__(self,other):
        return self.id < other.id

    def __gt__(self,other):
        return self.id > other.id

    def __eq__(self,other):
        if other == None:
            return False
        elif self.id == other.id:
            return True
        else:
            return False

    def __hash__(self):
        return id(self)

    def __iter__(self):
        yield from self.__values
