import random'''纸牌11点游戏规则:1. 3个人参与,默认先给用户发一张牌,其中 J、Q、K、小王、大王代表的值为0.5,其他就是则就是当前的牌面值。2. 随机顺序开始轮流抽牌,可以不抽,就得到点数3. 超过11点爆炸出局,最接近11点的获胜result={'player1':10, 'player2':8, 'player3':0}'''# 生成一副牌. The suits are called hearts, clubs, diamonds and spades.poker_cards = []for s in ['黑桃', '草花', '红心', '方片']: for n in range(1, 14): poker_cards.append((s, n))poker_cards.append(('joker', 14))poker_cards.append(('joker', 15))# print(poker_cards)# print(len(poker_cards))# 生成玩家players = []play_num = int(input("几个人玩 ? "))for i in range(play_num): players.append(input("玩家 {}:".format(i + 1)))print(players)result = {}# 生成当前玩家过程while players: Now_player = players.pop(random.randint(0, len(players) - 1)) Now_pick = [] while True: msg1 = "{player},你要抽牌还是不抽?(y/n)".format(player=Now_player) choice = input(msg1) if choice.lower() == 'y': pick_card = poker_cards.pop(random.randint(0, len(poker_cards) - 1)) Now_pick.append(pick_card) if 1 <= pick_card[1] <= 10: card_value = pick_card[1] else: card_value = 0.5 player_score = result.get(Now_player, 0) player_score += card_value result[Now_player] = player_score if player_score <= 11: msg2 = "{player},你抽到的牌是:{pick},现有牌组{cards},你的总分是 {score} .".format(player=Now_player, pick=pick_card, cards=Now_pick, score=player_score) print(msg2) else: player_score = 0 result[Now_player] = player_score msg3 = "{player},你抽到的牌是:{pick},现有牌组{cards},总分>11,你爆了,分数归0".format(player=Now_player, pick=pick_card, cards=Now_pick, ) print(msg3) break elif choice.lower() == 'n': player_score = result.get(Now_player, 0) msg4 = "{player},你选择不抽牌,你的总分是 {score} . 等待结果吧".format( player=Now_player, cards=Now_pick, score=player_score) print(msg4) result[Now_player] = player_score break else: print("输入错误,请重试。")for k, v in result.items(): msg5 = "{@R_301_6889@} 的总分是 {score}".format(@R_301_6889@=k, score=v) print(msg5)@H_419_1@# 结果演示:## 几个人玩 ? 3# 玩家 1:a# 玩家 2:b# 玩家 3:c# ['a', 'b', 'c']# c,你要抽牌还是不抽?(y/n)y# c,你抽到的牌是:('草花', 12),现有牌组[('草花', 12)],你的总分是 0.5 .# c,你要抽牌还是不抽?(y/n)y# c,你抽到的牌是:('红心', 8),现有牌组[('草花', 12), ('红心', 8)],你的总分是 8.5 .# c,你要抽牌还是不抽?(y/n)n# c,你选择不抽牌,你的总分是 8.5 . 等待结果吧# b,你要抽牌还是不抽?(y/n)y# b,你抽到的牌是:('黑桃', 7),现有牌组[('黑桃', 7)],你的总分是 7 .# b,你要抽牌还是不抽?(y/n)y# b,你抽到的牌是:('草花', 5),现有牌组[('黑桃', 7), ('草花', 5)],总分>11,你爆了,分数归0# a,你要抽牌还是不抽?(y/n)n# a,你选择不抽牌,你的总分是 0 . 等待结果吧# c 的总分是 8.5# b 的总分是 0# a 的总分是 0@H_419_1@总结
以上是内存溢出为你收集整理的扑克11点游戏(python代码)全部内容,希望文章能够帮你解决扑克11点游戏(python代码)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
概述importrandom'''纸牌11点游戏规则:1.3个人参与,默认先给用户发一张牌,其中J、Q、K、小王、大王代表的值为0.5,其他就是则就是当前的牌面值。2.随机顺序开始轮流抽牌,可以不抽,就得到点数3.超过11点爆炸出局,最接近11点的获胜result={'player1':10,'player2':8,
赞
(0)
打赏
微信扫一扫
支付宝扫一扫
C#中调用python
上一篇
2022-06-03
Python斗地主扑克牌游戏
下一篇
2022-06-03
评论列表(0条)