Python3模拟斗地主发牌

模拟斗地主发牌,牌共54张,

花色:黑桃('\u2660'),梅花('\u2663'),方块('\u2665'),红桃(‘\u2666’),种类为:A2-10JQK,大小王(X, x)

   三个人,每个人17张牌,牌底留三张
   输入回车,打印第一个问的17张牌
   输入回车,打印第二个问的17张牌

   输入回车,打印第三个问的17张牌

import random as R
""" 实现一人一次随机发17张牌"""
def reduce(L, w):     for x in w:         L.pop(L.index(x))     return L L = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'] H = ['\u2660', '\u2663', '\u2665', '\u2666'] P = ['X','x'] for x in H:     for y in L:         s = x + y         P.append(s) R.shuffle(P) i = 0 L2 = [] while i < 2:     if len(P) > 17:         w = R.sample(P, 17) # 从序列中选择n个随机且不重复的元素         L2.append(w)         P = reduce(P, w)         print(w)         input()     else:         break print(P)
import random as R
"""上面代码的简单实现"""

L = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
L1 = ['X', 'x']

L1.extend(map(lambda x: x+"\u2660", L))
L1.extend(map(lambda x: x+"\u2663", L))
L1.extend(map(lambda x: x+"\u2665", L))
L1.extend(map(lambda x: x+"\u2666", L))

R.shuffle(L1)
print(L1[0:17])
input()
print(L1[17:34])
input()
print(L1[34:51])
input()
print(L1[51:])
import random as R
"""一次一人发一张牌"""

L = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
H = ['\u2660', '\u2663', '\u2665', '\u2666']
w1 = []
w2 = []
w3 = []

P = ['X','x']
for x in H:
    for y in L:
        s = x + y
        P.append(s)

R.shuffle(P)

i = 1
while i <= 17:
    w1.append(P.pop())
    w2.append(P.pop())
    w3.append(P.pop())
    i += 1

print(w1)
input()
print(w2)
input()
print(w3)
input()
print(P)



你可能感兴趣的:(Python,Python,模拟斗地主发牌)