parent
3d22b695e6
commit
d8a333978b
|
|
@ -0,0 +1,16 @@
|
||||||
|
class ChengduMahjongState:
|
||||||
|
def __init__(self):
|
||||||
|
# 每个玩家的手牌
|
||||||
|
self.hands = [[0] * 108 for _ in range(4)] # 每个玩家108张牌的计数
|
||||||
|
# 每个玩家的打出的牌
|
||||||
|
self.discards = [[] for _ in range(4)] # 每个玩家的弃牌列表
|
||||||
|
# 每个玩家的明牌(碰、杠)
|
||||||
|
self.melds = [[] for _ in range(4)]
|
||||||
|
# 剩余的牌堆
|
||||||
|
self.deck = list(range(108)) # 0-107 表示108张牌
|
||||||
|
# 当前玩家索引
|
||||||
|
self.current_player = 0
|
||||||
|
# 剩余牌数量
|
||||||
|
self.remaining_tiles = 108
|
||||||
|
# 胜利玩家列表
|
||||||
|
self.winners = []
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
def can_win(hand):
|
||||||
|
# 判断是否满足胡牌条件
|
||||||
|
...
|
||||||
|
|
||||||
|
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
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
def get_suit(tile_index):
|
||||||
|
"""
|
||||||
|
根据牌的索引返回花色。
|
||||||
|
条:索引 0-35,筒:索引 36-71,万:索引 72-107
|
||||||
|
"""
|
||||||
|
suits = ["条", "筒", "万"]
|
||||||
|
return suits[tile_index // 36]
|
||||||
Loading…
Reference in New Issue