1
1
This commit is contained in:
@@ -95,3 +95,30 @@ def check_blood_battle(self):
|
||||
if len(self.state.winners) >= 3 or self.state.remaining_tiles == 0:
|
||||
logger.info(f"游戏结束,赢家列表: {self.state.winners}")
|
||||
self.game_over = True
|
||||
|
||||
|
||||
def set_missing_suit(player, missing_suit, game_state):
|
||||
"""
|
||||
玩家设置缺门的动作。
|
||||
|
||||
参数:
|
||||
- player: 玩家索引(0-3)。
|
||||
- missing_suit: 玩家选择的缺门("条"、"筒" 或 "万")。
|
||||
- game_state: 当前的游戏状态(`ChengduMahjongState` 实例)。
|
||||
|
||||
异常:
|
||||
- ValueError: 如果缺门设置无效。
|
||||
"""
|
||||
valid_suits = ["条", "筒", "万"]
|
||||
if missing_suit not in valid_suits:
|
||||
logger.error(f"玩家 {player} 尝试设置无效的缺门: {missing_suit}")
|
||||
raise ValueError("缺门设置无效")
|
||||
|
||||
if game_state.missing_suits[player] is not None:
|
||||
logger.error(f"玩家 {player} 已经设置了缺门,不能重复设置")
|
||||
raise ValueError("缺门已经设置,不能重复设置")
|
||||
|
||||
game_state.missing_suits[player] = missing_suit
|
||||
logger.info(f"玩家 {player} 设置缺门为: {missing_suit}")
|
||||
|
||||
return game_state.missing_suits[player]
|
||||
@@ -1,8 +1,35 @@
|
||||
from .game_state import ChengduMahjongState
|
||||
|
||||
from .utils import get_suit, get_tile_name
|
||||
from loguru import logger
|
||||
|
||||
class ChengduMahjongEngine:
|
||||
def __init__(self):
|
||||
self.state = ChengduMahjongState()
|
||||
self.state = ChengduMahjongState() # 创建游戏状态
|
||||
self.game_over = False
|
||||
self.deal_tiles() # 发牌
|
||||
|
||||
def deal_tiles(self):
|
||||
""" 发牌,每个玩家发13张牌,并设置缺门 """
|
||||
logger.info("发牌中...")
|
||||
# 随机发牌给每个玩家
|
||||
for player in range(4):
|
||||
for _ in range(13): # 每个玩家13张牌
|
||||
tile = self.state.deck.pop()
|
||||
self.state.hands[player][tile] += 1 # 增加玩家手牌的计数
|
||||
|
||||
# 设置缺门:每个玩家定缺
|
||||
for player in range(4):
|
||||
self.state.set_missing_suit(player, missing_suit)
|
||||
|
||||
def start_game(self):
|
||||
""" 开始游戏 """
|
||||
# 游戏开始时初始化状态等
|
||||
self.game_over = False
|
||||
logger.info("游戏开始!")
|
||||
|
||||
def check_game_over(self):
|
||||
""" 检查游戏是否结束 """
|
||||
# 你可以根据游戏规则检查是否有玩家胡牌或其他结束条件
|
||||
if len(self.state.deck) == 0:
|
||||
self.game_over = True
|
||||
logger.info("游戏结束!")
|
||||
|
||||
@@ -36,11 +36,8 @@ class ChengduMahjongState:
|
||||
"""
|
||||
valid_suits = ["条", "筒", "万"]
|
||||
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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user