Compare commits
2 Commits
b7bd0a7037
...
d8a333978b
| Author | SHA1 | Date | |
|---|---|---|---|
| d8a333978b | |||
| 3d22b695e6 |
13
src/engine/actions.py
Normal file
13
src/engine/actions.py
Normal file
@@ -0,0 +1,13 @@
|
||||
def draw_tile(state):
|
||||
if state.remaining_tiles == 0:
|
||||
raise ValueError("牌堆已空")
|
||||
tile = state.deck.pop(0)
|
||||
state.remaining_tiles -= 1
|
||||
state.hands[state.current_player][tile] += 1
|
||||
return tile
|
||||
|
||||
def discard_tile(state, tile):
|
||||
if state.hands[state.current_player][tile] == 0:
|
||||
raise ValueError("玩家没有这张牌")
|
||||
state.hands[state.current_player][tile] -= 1
|
||||
state.discards[state.current_player].append(tile)
|
||||
16
src/engine/game_state.py
Normal file
16
src/engine/game_state.py
Normal 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
13
src/engine/scoring.py
Normal 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
7
src/engine/utils.py
Normal file
@@ -0,0 +1,7 @@
|
||||
def get_suit(tile_index):
|
||||
"""
|
||||
根据牌的索引返回花色。
|
||||
条:索引 0-35,筒:索引 36-71,万:索引 72-107
|
||||
"""
|
||||
suits = ["条", "筒", "万"]
|
||||
return suits[tile_index // 36]
|
||||
Reference in New Issue
Block a user