用python模拟斗地主发牌过程
本帖最后由 yangbaowen 于 2022-4-4 23:07 编辑要求:(1)三人制斗地主,每人17张牌,留有三张底牌。
(2)大小顺序:大小王,2,A,以及K到3(3为最小)。
(3)同一大小的牌按照黑桃,红桃,梅花,方块的顺序排列。
(4)最后展示出3个玩家的牌,以及底牌。 本帖最后由 yangbaowen 于 2022-4-4 19:09 编辑
order = 1 #代表牌的排列顺序
Player_Num = 3 #代表玩家数目
N = 54
times = 1
leftover = 3 #代表给地主留的底牌数目
import random
card0 = list(range(0,N))
card0 = card0*times
#print(card0)
schar = '♠♥♣♦🃏🃏'
card1 = []
left = N*times
for i in range(N*times):
rdi = random.randint(0,left-1)
card1.append(card0)
card0.pop(rdi)
left-=1
if left==0:
break
#print(card1)
Player = []
for i in range (Player_Num):
Player.append([])
for i in range (N*times - leftover):
Player.append(card1)
Player.append([])
for i in range (N*times-leftover,N*times):
Player.append(card1)
for i in range(Player_Num + 1):
#print(Player)
card_output = []
for i in range (Player_Num + 1):
card_output.append([])
for i in range(Player_Num + 1):
for j in range(len(Player)):
if Player == 53 or Player == 52:
card_output.append(str(schar%2 + 4]).rjust(3))
else:
cardnumber = (Player // 4 + 2)%13 + 1
cardflower =3-Player % 4
if cardnumber == 1:
card_output.append('A'.rjust(2)+str(schar))
elif cardnumber == 11:
card_output.append('J'.rjust(2)+str(schar))
elif cardnumber == 12:
card_output.append('Q'.rjust(2)+str(schar))
elif cardnumber == 13:
card_output.append('K'.rjust(2)+str(schar))
else:
card_output.append(str(cardnumber).rjust(2)+str(schar))
#print(card_output)
for i in range (Player_Num):
print('玩家{:>2}的手牌为:'.format(i+1),''.join(card_output))
print('剩余的{}张底牌为:'.format(leftover),''.join(card_output))
页:
[1]