import random class DouDiZhu: def __init__(self): self.deck = self.create_deck() self.players = {'玩家1': [], '玩家2': [], '玩家3': []} self.bottom_cards = [] def create_deck(self): suits = ['♠', '♥', '♣', '♦'] values = ['2', 'A', 'K', 'Q', 'J', '10', '9', '8', '7', '6', '5', '4', '3'] deck = [suit + value for suit in suits for value in values] deck += ['BJ', 'RJ'] return deck def shuffle_and_deal(self): random.shuffle(self.deck) self.players['玩家1'] = self.deck[:17] self.players['玩家2'] = self.deck[17:34] self.players['玩家3'] = self.deck[34:51] self.bottom_cards = self.deck[51:] def swap_cards(self): self.players['玩家1'], self.players['玩家2'], self.players['玩家3'] = \ self.players['玩家2'], self.players['玩家3'], self.players['玩家1'] def display_cards(self, title): print(title) for player, cards in self.players.items(): print(f"{player}: {' '.join(cards)}") print() game = DouDiZhu() game.shuffle_and_deal() game.display_cards("交换前") game.swap_cards() game.display_cards("交换后")
斗地主换牌程序
最新推荐文章于 2024-08-15 01:55:01 发布