Created
February 16, 2018 23:10
-
-
Save ledrui/4be3885b56756345a7c4e535fcd3e7f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# card mapped to digits from 1 to 13 | |
# A,2,3,4,5,6,7,8,9,10,J, Q, K | |
# [1 2 3 4 5 6 7 8 9 10 11 12 13] | |
# [1,2,2,4] | |
# [k, 2, k, 2, 2] # <<<<<<<<< | |
# [13, 2,13,2, 2] | |
# 13 -> 2 | |
# 2 -> 3 | |
def hand_type(hand): | |
types = [ 0 for x in range(14) ] # [0,0,0,0,0000] | |
result = -1 | |
type_count = [] | |
for card in hand: | |
types[card] += 1 | |
for count in types: | |
if count != 0: | |
type_count.append(count) # put all non zero count in a list for easy check | |
# if any card count to 4 we have 4 of kind | |
if 4 in type_count : | |
result = 7 | |
elif 3 in type_count: # we can have at least "3 of kind" | |
if 2 in type_count: | |
result = 6 # "Full house" | |
else: | |
result = 5 # "3 of kind" | |
elif 2 in type_count: # we can have at least 1 pair | |
if len(type_count) == 4: | |
result = 1 # we have "1 pair" | |
else: | |
result = 2 # we have "2 pair" | |
else: | |
result = 0 # we have "high card" | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment