import random
import itertools
import time
strtime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
print(strtime)
a=['♥','♠','♦','♣']
b=['A','2','3','4','5','6','7','8','9','10','J','Q','K']
c=[i+j for i in a for j in b]
random.shuffle(c)
def tra(x):
L=[]
for i in x:
JQK=['0','J','Q','K']
if i[-1] in JQK:
num=10
elif i[-1]=='A':
num=1
else:
num=int(i[-1])
L.append(num)
d=list(itertools.permutations(L,3))
for i in d:
if sum(i)%10==0:#所有列举的三个数加起来能被10整除
if sum(L)%10==0:
return 10#5个数能被10整除
return sum(L)%10
else:
return 0
def cpu(x):
print '开始给电脑发牌:'
time.sleep(1)
for i in x:
print i,
def play(x):
print '开始给玩家发牌:'
time.sleep(1)
for i in x:
print i,
def xipai(y):
for i in y:
c.remove(i)
def game():
print '-------------你现在有%d元---------------'%s
print '-------------电脑现在有%d元---------------'%pcmoney
time.sleep(1)
print '------------游戏开始------------ '
def jieguo(poker):
if tra(poker)==10:
print (u"满牛")
elif 0<tra(poker)<10:
print '牛%d'%tra(poker)
else:
print u'没牛'
def wl(x,y):
global s
global pcmoney
if tra(x)>tra(y):
if tra(x)==10:
time.sleep(2)
print '哈哈你输了{0}元'.format(2*pcxzmoney)
pcmoney=pcmoney+2*pcxzmoney
s=s-pcxzmoney*2
time.sleep(1)
print '你现在有%d元'%(s)
print '电脑现在有%d元'%pcmoney
else:
time.sleep(2)
print '哈哈你输了%d元'%pcxzmoney
pcmoney=pcmoney+pcxzmoney
s=s-pcxzmoney
time.sleep(1)
print '你现在有%d元'%(s)
print '电脑现在有%d元'%pcmoney
elif tra(x)<tra(y):
if tra(y)==10:
time.sleep(2)
print '恭喜你赢了{0}元'.format(2*money)
pcmoney=pcmoney-2*money
s=s+money*2
time.sleep(1)
print '你现在有%d元'%(s)
print '电脑现在有%d元'%pcmoney
else:
time.sleep(2)
print '恭喜你赢了%d元'%money
pcmoney=pcmoney-money
s=s+money
time.sleep(1)
print '你现在有%d元'%(s)
print '电脑现在有%d元'%pcmoney
else:
time.sleep(2)
print '平 手'
time.sleep(1)
print '你现在有%d元'%s
print '电脑现在有%d元'%pcmoney
s=1000
pcmoney=1000
if __name__ == '__main__':
print '--------------你有1000元本金----------------'
print '-------------电脑也有1000元本金----------------'
print '-------------谁先输到0元谁就输----------------'
while s>0 and pcmoney>0:
game()
try:
money=int(input('请下注金额:'))
while money<=0 or money>s:
money=int(input('下注金额输入错误,请重新输入下注金额:'))
pcxzmoney=random.randint(1,pcmoney)
time.sleep(2)
print '电脑下注金额为:%d'%pcxzmoney
poker=random.sample(c,5)
time.sleep(2)
cpu(poker)
time.sleep(1)
jieguo(poker)
xipai(poker)
time.sleep(1)
pk=random.sample(c,5)
play(pk)
jieguo(pk)
wl(poker,pk)
if s<=0:
print '游 戏 结 束!'
print '你输了'
elif pcmoney<=0:
print '游 戏 结 束!'
print '你赢了'
else:
print "请继续,你怎么还没把电脑打败"
except:
print '格式错误'
满牛时赢得钱为2倍