Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- def bubbleSort(arr):
- isSorted = False
- while not(isSorted):
- for i in range(len(arr) - 1):
- for j in range(len(arr) - 1 - i):
- if arr[j] > arr[j+1]:
- arr[j], arr[j+1] = arr[j+1],arr[j]
- else:
- isSorted = True
- return (arr)
- def occur(cards):
- scorelist = [2,4,8]
- counter = collections.Counter(cards)
- largest = [0,0]
- largest2 = [0,0]
- for key in counter:
- occur = counter[key]
- if occur > largest2[1]:
- if occur > largest[1]:
- largest2 = largest
- largest = [key,occur]
- else:
- largest2 = [key,occur]
- num = max([largest[0],largest2[0]])
- if largest[1] == 3 and largest2[1] == 2:
- return(7,largest[0])
- elif largest[1] == largest2[1]:
- return(3,num)
- elif largest[1] in [2,3,4]:
- return(scorelist[[2,3,4].index(largest[1])],num )
- return(1,num)
- def flush(cards):
- counter = collections.Counter(cards)
- if len(counter) == 1:
- return(True,max(cards))
- return(False,max(cards))
- def straight(cards):
- if cards[4] - cards[0] == 4:
- return(True,max(cards))
- return(False,max(cards))
- def royal(cards):
- royal = [1,10,11,12,13]
- if cards == royal:
- return(True,13)
- return(False,13)
- values = [1,2,2,4,5]
- suits = [1,1,2,1,1]
- #score: 1(highcard)|2(pair)|3(two pair)|4(three of a kind)|5(straight)|6(flush)|7(full house)|8(four of a kind)|9(straight flush)|10(royal flush|
- def handLogic(values,suits):
- values = bubbleSort(values)
- suits = bubbleSort(suits)
- occurances = occur(values)
- if occurances == 2:
- if flush(suits) == 5:
- if straight(values):
- return(9)
- if royal(values):
- return(10)
- return(6)
- if straight(values):
- return(5)
- return(1)
- return(occurances)
- print("score: " + str(handLogic(values,suits)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement