1
This commit is contained in:
2024-12-01 22:14:23 +08:00
parent 5eef2384cf
commit 3e65e02704
29 changed files with 87 additions and 39 deletions

View File

@@ -0,0 +1,37 @@
from src.engine.mahjong.mahjong_tile import MahjongTile
class Meld:
def __init__(self, tile, type: str):
"""
初始化一个碰或杠的对象。
:param tile: MahjongTile 对象,表示碰或杠的牌。
:param type: 字符串,'''',表示碰或杠。
"""
if not isinstance(tile, MahjongTile):
raise TypeError("tile 必须是 MahjongTile 类型")
if type not in ['', '']:
raise ValueError("type 必须是 ''''")
self.tile = tile
self.type = type
self.count = 3 if type == '' else 4 # 碰为3张杠为4张
def __repr__(self):
return f"({self.type}: {self.tile} x{self.count})"
def __eq__(self, other):
if not isinstance(other, Meld):
return False
return self.tile == other.tile and self.type == other.type
def __hash__(self):
return hash((self.tile, self.type))
def is_triplet(self):
"""是否为碰"""
return self.type == ''
def is_kong(self):
"""是否为杠"""
return self.type == ''