22 lines
565 B
Python
22 lines
565 B
Python
class MahjongTile:
|
|
SUITS = ['条', '筒', '万']
|
|
|
|
def __init__(self, suit, value):
|
|
if suit not in self.SUITS or not (1 <= value <= 9):
|
|
raise ValueError("Invalid tile")
|
|
self.suit = suit
|
|
self.value = value
|
|
self.index = ({"条": 0, "筒": 1, "万": 2}[suit]) * 9 + (value - 1)
|
|
|
|
def __repr__(self):
|
|
return f"{self.value}{self.suit}"
|
|
|
|
def __eq__(self, other):
|
|
return self.suit == other.suit and self.value == other.value
|
|
|
|
def __hash__(self):
|
|
return hash((self.suit, self.value))
|
|
|
|
|
|
|