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

``````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())

``````

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(...)

``````