wsy182 2024-11-30 13:28:59 +08:00
parent 3d22b695e6
commit d8a333978b
3 changed files with 36 additions and 0 deletions

16
src/engine/game_state.py Normal file
View File

@ -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 = []

13
src/engine/scoring.py Normal file
View File

@ -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

7
src/engine/utils.py Normal file
View File

@ -0,0 +1,7 @@
def get_suit(tile_index):
"""
根据牌的索引返回花色
索引 0-35索引 36-71索引 72-107
"""
suits = ["", "", ""]
return suits[tile_index // 36]