I'm trying to create a program that allows users to play poker (for fake money, don't come after me IRS), and had a problem trying to determine kickers for better hands. So initially my thought was to sort the values of the cards (without suits) which I have like [14, 12, 10, 8, 6]
(with 14 for ace high). And compare it to another list, say [14, 12, 10, 8, 7]
(7 kicker) to see which ranks higher. Each hand comes from one of the 5 card combinations from the 7 available cards in a hold 'em game. My initial thought was to do:
def better_hand_with_kicker(list0, list1):
for index in range(5):
if list0[index] >= list1[index]:
continue
else:
return False
return True
Yet, this won't work if any number was smaller. For instance between [14, 12, 10, 8, 6]
and [14, 13, 9, 7, 5]
it will return that [14, 12, 10, 8, 6]
is superior because even though (13 > 12) makes the other hand win, the third slot of (9 < 10) will trigger the return False
clause.
Therefore I thought of a slightly more complex:
def better_hand_with_kicker(list0, list1):
for index in range(5):
if list0[index] == list1[index]:
continue
elif list0[index] > list1[index]:
return True
else:
return False
return True # this would really be a tie
Now this works, but I figure there must be a much more elegant solution...