parent
5aa40d1dd5
commit
daec029789
|
|
@ -1,4 +1,4 @@
|
|||
from random import random
|
||||
import random as random_module
|
||||
|
||||
from loguru import logger
|
||||
from src.engine.mahjong_tile import MahjongTile
|
||||
|
|
@ -203,7 +203,7 @@ def check_other_players(self, tile):
|
|||
continue
|
||||
|
||||
# 优先检查胡牌
|
||||
if self.can_win(self.state.hands[player], self.state.melds[player], self.state.missing_suits[player]):
|
||||
if self.state.can_win(self.state.hands[player], self.state.melds[player], self.state.missing_suits[player]):
|
||||
logger.info(f"玩家 {player} 可以胡玩家 {current_player} 的牌: {tile}")
|
||||
handle_win(player, current_player, tile)
|
||||
actions_taken = True
|
||||
|
|
@ -346,10 +346,6 @@ def random_discard_tile(engine):
|
|||
def random_choice(hand, missing_suit):
|
||||
"""
|
||||
根据缺门优先随机选择打出的牌。
|
||||
|
||||
:param hand: 当前玩家的手牌(列表,包含 MahjongTile 对象)。
|
||||
:param missing_suit: 当前玩家的缺门花色(字符串)。
|
||||
:return: 随机选择的 MahjongTile 对象。
|
||||
"""
|
||||
if not hand:
|
||||
raise ValueError("手牌不能为空")
|
||||
|
|
@ -359,11 +355,11 @@ def random_choice(hand, missing_suit):
|
|||
|
||||
# 如果缺门牌存在,优先从缺门牌中随机选择
|
||||
if missing_suit_tiles:
|
||||
index = random.randint(0, len(missing_suit_tiles) - 1)
|
||||
index = random_module.randint(0, len(missing_suit_tiles) - 1)
|
||||
return missing_suit_tiles[index]
|
||||
|
||||
# 如果缺门牌不存在,从剩余牌中随机选择
|
||||
index = random.randint(0, len(hand) - 1)
|
||||
index = random_module.randint(0, len(hand) - 1)
|
||||
return hand[index]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class ChengduMahjongEngine:
|
|||
logger.info(f"玩家 {self.current_player} 杠牌,类型: {gang_type}")
|
||||
else:
|
||||
title = random_choice(self.state.hands[self.current_player], self.state.missing_suits[self.current_player])
|
||||
check_other_players(self.state.hands[self.current_player], title)
|
||||
check_other_players(self, title)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue