This commit is contained in:
2024-11-30 19:15:24 +08:00
parent 2a5680fae9
commit 9f7a22be7f
4 changed files with 54 additions and 22 deletions

View File

@@ -55,7 +55,7 @@ def peng(self, tile):
logger.info(f"玩家 {player} 碰了一张牌: {tile_name}(索引 {tile})。当前明牌: {self.state.melds[player]}")
def gang(self, tile, mode="ming"):
def gang(self, tile, mode):
"""
当前玩家杠牌逻辑,记录杠牌类型和状态更新。
"""

View File

@@ -67,13 +67,23 @@ def is_seven_pairs(hand):
return sum(1 for count in hand if count == 2) == 7
def is_cleared(hand):
def is_cleared(hand, melds):
"""
检查手牌是否是清一色。
"""
suits = [tile // 36 for tile, count in enumerate(hand) if count > 0]
return len(set(suits)) == 1
检查手牌和明牌是否是清一色。
参数:
- hand: 当前胡牌的手牌长度为108的列表表示每张牌的数量
- melds: 碰杠等明牌列表。
返回:
- bool: 是否为清一色。
"""
# 获取所有牌的花色
all_tiles = hand + [tile for meld in melds for tile in meld]
suits = [tile // 36 for tile in all_tiles if tile > 0]
# 检查是否有多种花色
return len(set(suits)) == 1
def is_big_pairs(hand):
"""

View File

@@ -38,9 +38,9 @@ class ChengduMahjongState:
if missing_suit not in valid_suits:
logger.error(f"玩家 {player} 尝试设置无效的缺门: {missing_suit}")
raise ValueError("缺门设置无效")
self.missing_suits[player] = missing_suit
logger.info(f"玩家 {player} 设置缺门为: {missing_suit}")
return self.missing_suits[player]
def can_win(self, hand):
"""