【Python】利用装饰器实现斗地主之洗牌和抓牌,效果杠杠的!

import random
str_L=['2','3','4','5','6','7','8','9','10','J','Q','K','A']
color_L=['红桃','黑桃','方块','梅花']
l=['大王','小王']
for i in str_L:
	for j in color_L:
		l.append(j+i)
#洗牌
def washCards(func):
	def wrapper():
		random.shuffle(l)
		print("洗牌:"+str(l))
		func()
	return wrapper
#抓牌
@washCards
def catchCards():
	lA,lB,lC=[],[],[]
	for i in range(0,51,3):
		lA.append(l[i])
	print("玩家A:"+str(lA))
	for j in range(1,51,3):
		lB.append(l[j])
	print("玩家B:"+str(lB))
	for k in range(2,51,3):
		lC.append(l[k])
	print("玩家C:"+str(lC))
	for x in lA+lB+lC:
		l.remove(x)
	print("地主:"+str(l))
if __name__=="__main__":
	catchCards()

【Python】利用装饰器实现斗地主之洗牌和抓牌,效果杠杠的!_第1张图片

你可能感兴趣的:(Python,装饰器,python游戏,人工智能)