python中关于模拟扑克牌游戏的发牌中要求添加大小猫和留底牌,该怎么在原有的基础上实现了?

以下是实现52张牌,随机打乱后分发给4个人的代码

import random
print("扑克游戏发牌模拟")
ranks=('2','3','4','5','6','7','8','9','10','J','Q','K','A')
suits=('黑桃','红桃','方块','黑桃、、梅花')
puke=[(x,y)for x in suits for y in ranks]
pai=puke*2
cardRand = random.sample(pai,104)
play1=[]
play2=[]
play3=[]
play4=[]
for i in range(26):
    play1.append(cardRand.pop())
    play2.append(cardRand.pop())
    play3.append(cardRand.pop())
    play4.append(cardRand.pop())
play1.sort(key=lambda x:x[0])
play2.sort(key=lambda x:x[0])
play3.sort(key=lambda x:x[0])
play4.sort(key=lambda x:x[0])
print("玩家1的牌")
i=1
for each in play1:
    print(each,end=',')
    if(i%6==0):
        print()
    i=i+1
print("玩家2的牌")
i=1
for each in play2:
    print(each,end=',')
    if(i%6==0):
        print()
    i=i+1
print("玩家3的牌")
i=1
for each in play3:
    print(each,end=',')
    if(i%6==0):
        print()
    i=i+1
print("玩家4的牌")
i=1
for each in play4:
    print(each,end=',')
    if(i%6==0):
        print()
    i=i+1

实现增添以上功能,该如何实现

2个回答

suits=('黑桃','红桃','方块','黑桃、、梅花')
->
suits=('黑桃','红桃','方块','梅花')
puke=[(x,y)for x in suits for y in ranks]
pai.append('大猫')
pai.append('小猫')
pai=puke*2
cardRand = random.sample(pai,108)
...
for i in range(25): //比如说留8张底牌,这里少1
    play1.append(cardRand.pop())
    play2.append(cardRand.pop())
    play3.append(cardRand.pop())
    play4.append(cardRand.pop())

weixin_42572594
隨緣少年 谢谢指导!
5 个月之前 回复
puke=[(x,y)for x in suits for y in ranks] + ['大猫', '小猫']
//发牌的逻辑整理进这个函数
def distCards(cardList, cards):
    for i in range(cards):
        player[i%4].append(...)


这样要留底牌的话写distCards(puke, 52 - ?)就行

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问