62 lines
1.6 KiB
Python

#valuetab = ('High Card', 'One Pair', 'Two Pairs', 'Three of a Kind', 'Straight', 'Flush', 'Full House', 'Four of a Kind', 'Straight Flush', 'Royal Flush')
trans = {'A':14, 'T':10, 'J':11, 'Q':12, 'K':13}
def calc(x):
color = []
num = []
for i in x:
color.append(i[1])
if '1' < i[0] <= '9':
num.append(ord(i[0]) - ord('0'))
else:
num.append(trans.get(i[0]))
num.sort()
num.append(0)
step = 1
dic = {4:[], 3:[], 2:[], 1:[]}
same = 1
for i in range(1, len(num)):
diff = num[i] - num[i - 1]
if diff == 0:
same += 1
else:
dic.get(same).append(num[i - 1])
same = 1
if diff == 1:
step += 1
if len(dic.get(4)):
return (7, dic.get(4)[0], dic.get(1))
if len(dic.get(3)) == len(dic.get(2)) == 1:
return (6, dic.get(3)[0], dic.get(2)[0])
flag = 0
if len(set(color)) == 1:
if step == 5:
return (8, dic.get(1)[-2])
flag = 5
if step == 5:
return (flag, 4, num[-2])
if len(dic.get(3)):
dic.get(1).reverse()
return (flag, 3, dic.get(3)[0], dic.get(1))
if len(dic.get(2)) > 1:
dic.get(2).reverse()
return (flag, 2, dic.get(2), dic.get(1))
dic.get(1).reverse()
if len(dic.get(2)):
return (flag, 1, dic.get(2)[0], dic.get(1))
return (flag, 0, dic.get(1))
def main():
ff = open('../resource/poker.txt', 'r')
out = 0
for line in ff.readlines():
strlis = line.split(' ')
if calc(strlis[0:5]) > calc(strlis[5:]):
out += 1
ff.close()
return out
#print calc(['7C','4C','4C','4C','7C'])
print(main())