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):
- 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,counter[key]]
- else:
- largest2 = [key,counter[key]]
- if largest[1] + largest2[1] == 5:
- return(7)
- elif largest[1] in [1,2,3]:
- return(largest[1] + 1)
- else:
- return(8)
- # if 2 highest are the same, is a 2 pair :DDDDD
- def flush(cards):
- counter = collections.Counter(cards)
- if len(counter) == 1:
- return(True)
- return(False)
- def straight(cards):
- if cards[4] - cards[0] == 4:
- return(True)
- return(False)
- def royal(cards):
- royal = [1,10,11,12,13]
- if cards == royal:
- return(True)
- return(False)
- 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