Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def convert(letter):
- if letter in "TJQKA":
- return 10 + "TJQKA".index(letter)
- else:
- return int(letter)
- def straight(n):
- nn = sorted(n)
- for x in range(4):
- if nn[x] + 1 != nn[x+1]:
- return False
- return True
- def rank(hand):
- nums, suits = [], []
- for x in hand:
- nums.append(convert(x[0]))
- for x in hand:
- suits.append(x[1])
- print(sorted(nums), sorted(suits))
- if sorted(nums) == [10, 11, 12, 13, 14] and len(set(suits)) == 1:
- return 9
- elif len(set(suits)) == 1 and straight(nums):
- return 8, sorted(nums)[4]
- elif len(set(sorted(nums)[:4])) == 1 or len(set(sorted(nums)[1:])) == 1:
- if sorted(nums)[0] == sorted(nums)[1]:
- return 7, sorted(nums)[0]
- else:
- return 7, sorted(nums)[1]
- elif (len(set(sorted(nums)[:3])) == 1 or len(set(sorted(nums)[2:])) == 1) and len(set(sorted(nums))) == 2:
- if sorted(nums)[1] != sorted(nums)[2]:
- return 6, sorted(nums)[2]
- else:
- return 6, sorted(nums)[0]
- elif len(set(suits)) == 1:
- return 5, sorted(nums)[4]
- elif straight(nums):
- return 4, sorted(nums)[4]
- elif len(set(sorted(nums)[:3])) == 1 or len(set(sorted(nums)[1:4])) == 1 or len(set(sorted(nums)[2:])) == 1:
- for x in range(2, 15):
- count = 0
- for y in sorted(nums):
- if x == y:
- count += 1
- if count == 3:
- return 3, x
- elif len(set(sorted(nums))) == 3:
- return 2, sorted(nums)[3]
- elif len(set(sorted(nums))) == 4:
- for x in range(2, 15):
- count = 0
- for y in sorted(nums):
- if x == y:
- count += 1
- if count == 2:
- return 1, x
- else:
- return 0, sorted(nums)[4]
- file = list(open("poker.txt"))
- newfile = []
- for a in file:
- newfile.append(a.rstrip())
- file = []
- for b in newfile:
- temp = []
- tempstr = ""
- for c in b:
- tempstr += c
- if c == " ":
- temp.append(tempstr)
- tempstr = ""
- continue
- temp.append(tempstr)
- file.append(temp)
- answer, index = 0, 0
- for d in file:
- index += 1
- print(index)
- print(d[:5], d[5:])
- if list(rank(d[:5]))[0] > list(rank(d[5:]))[0]:
- answer += 1
- print("Won")
- elif list(rank(d[:5]))[0] == list(rank(d[5:]))[0]:
- if list(rank(d[:5]))[1] > list(rank(d[5:]))[1]:
- answer += 1
- print("Won")
- print(list(rank(d[:5])), list(rank(d[5:])))
- print(answer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement