import random
# 生成一副牌
def generate_cards():
suits = ['♠', '♥', '♣', '♦']
ranks = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
cards = [suit + rank for suit in suits for rank in ranks]
cards.append('小王')
cards.append('大王')
return cards
# 洗牌
def shuffle_cards(cards):
random.shuffle(cards)
# 发牌
def deal_cards(cards):
players = [[], [], []]
for i in range(3):
players[i] = cards[i::3]
return players
# 打印玩家手牌
def print_hand(player, cards):
print(f'玩家{player + 1}的手牌:')
for card in cards:
print(card, end=' ')
print()
# 主函数
def main():
cards = generate_cards()
shuffle_cards(cards)
players = deal_cards(cards)
for i in range(3):
print_hand(i, players[i])
if __name__ == '__main__':
main()
这个程序会生成一副牌,然后洗牌并发牌给三个玩家,最后打印每个玩家的手牌。
请注意,这只是一个简单的示例程序。如果要实现完整的斗地主游戏,还需要考虑牌型判断、出牌逻辑、游戏规则等更多内容。