Update chengdu_mahjong_engine.py
parent
65f036c318
commit
b7bd0a7037
|
|
@ -39,3 +39,51 @@ class ChengduMahjongEngine:
|
||||||
self.state.melds[player].append(("an_gang", tile))
|
self.state.melds[player].append(("an_gang", tile))
|
||||||
else:
|
else:
|
||||||
raise ValueError("杠牌条件不满足")
|
raise ValueError("杠牌条件不满足")
|
||||||
|
|
||||||
|
def set_missing_suit(player, missing_suit):
|
||||||
|
# 确定玩家的缺门
|
||||||
|
valid_suits = ["条", "筒", "万"]
|
||||||
|
if missing_suit not in valid_suits:
|
||||||
|
raise ValueError("缺门设置无效")
|
||||||
|
player.missing_suit = missing_suit
|
||||||
|
|
||||||
|
|
||||||
|
def check_blood_battle(self):
|
||||||
|
if len(self.winners) >= 3 or self.state.remaining_tiles == 0:
|
||||||
|
self.game_over = True
|
||||||
|
|
||||||
|
|
||||||
|
def can_win(hand):
|
||||||
|
# 判断是否满足胡牌条件(四组+一对)
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
|
# 判断缺一门
|
||||||
|
suits = [get_suit(tile) for tile, count in enumerate(hand) if count > 0]
|
||||||
|
if len(set(suits)) > 2:
|
||||||
|
return False # 不满足缺一门
|
||||||
|
|
||||||
|
# 判断是否满足四组+一对
|
||||||
|
def is_valid_group(tiles):
|
||||||
|
# 判断是否为顺子、刻子或对子
|
||||||
|
return len(tiles) == 3 and (tiles[0] == tiles[1] == tiles[2] or
|
||||||
|
tiles[0] + 1 == tiles[1] and tiles[1] + 1 == tiles[2])
|
||||||
|
|
||||||
|
counter = Counter(hand)
|
||||||
|
pairs = [tile for tile, count in counter.items() if count >= 2]
|
||||||
|
for pair in pairs:
|
||||||
|
temp_hand = hand[:]
|
||||||
|
temp_hand[pair] -= 2
|
||||||
|
if is_valid_group(temp_hand):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def calculate_fan(hand, melds, is_self_draw, is_cleared):
|
||||||
|
fan = 1 # 基本胡
|
||||||
|
if is_cleared:
|
||||||
|
fan += 2 # 清一色
|
||||||
|
if len(melds) >= 2:
|
||||||
|
fan += len(melds) # 根据杠加番
|
||||||
|
if is_self_draw:
|
||||||
|
fan += 1 # 自摸加番
|
||||||
|
return fan
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue