模擬鬥地主發牌,牌共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
r.shuffle(p)
i = 0
l2 =
while i < 2:
if len(p) > 17:
w = r.sample(p, 17) # 從序列中選擇n個隨機且不重複的元素
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
r.shuffle(p)
i = 1
while i <= 17:
i += 1
print(w1)
input()
print(w2)
input()
print(w3)
input()
print(p)
Python3 模擬鬥地主發牌
分析 1.撲克牌作為物件呈現 2.建立未發牌的牌堆的列表 3.建立三個玩家牌堆的列表 4.建立底牌的元組 5.最原始的牌堆初始化,將54張牌加入到牌堆 6.建立洗牌操作 7.建立發牌操作 import random class poke poke 撲克牌牌堆 p1 玩家一牌堆 p2 玩家二牌堆 p3...
鬥地主發牌
鬥地主的發牌 a 鬥地主的發牌 實現模擬鬥地主的功能 1.組合牌 2.洗牌 3.發牌 4.看牌 public class doudizhu 定義4個花色陣列 string colors 定義整數變數,作為鍵出現 int index 2 遍歷陣列,花色 點數的組合,儲存到map集合 for strin...
模擬鬥地主洗牌和發牌
分析 a 建立乙個牌盒 b 裝牌 c 洗牌 d 發牌 e 看牌 public class test system.out.println public static void main string args 定義乙個點陣列 string numbers for string c colors ar...