I'm making a quick and dirty poker game in python, and am having trouble determining which player wins the hand. I have functions that deal cards, determine the "value" of the hand in the way that 0-8 correspond to high card - straight flush, and then the key pieces of what makes each hand unique.
What I'm having trouble is determining who wins when there are two or more players with the same hand type (pair,two pair, etc), and even worse when they have the same pair, and I have to go down and look at the kickers.
I'm having trouble determining a good way to store the data, and compare it all together as I need. I don't want to include all of my functions to check hand values and whatnot as it would get way too long. I'm really interested in people's thoughts on how to store and compare this data, especially what is mentioned about hands with similar values (the stuff in bold)
Each Player's hand is represented by a dictionary entry, keyed by player number in the form
mydict = {(1 :(2,'Spades)), (2 :(3,'Diamonds')), etc}
players = 5
# Creates deck of cards and deals to each player
Cards = Shuffle_Deck(Suits,Values,1)
All_Players, Cards = deal_hand(players,5,Cards)
# scores and orders hands
def order_hands(All_Players):
rank_hands = []
for i in range(1,len(All_Players)+1):
rank_hands.append([i,score_hand(All_Players[i],printhand=False,printvalue=False)])
sorted_hands = rank_hands[:]
sorted_hands.sort(key=lambda x: x[1][0],reverse=True)
return sorted_hands
Sorted_Hands = order_hands(All_Players)
#print Sorted_Hands
def who_Wins(Sorted_Hands):
Tied_Hands = []
winning_index = Sorted_Hands[0][1][0]
for i in range(len(Sorted_Hands)):
if Sorted_Hands[i][1][0] == winning_index:
# print Sorted_Hands[i]
Tied_Hands.append([Sorted_Hands[i][0],Sorted_Hands[i][1][1:]])
return winning_index,Tied_Hands
winning_index,Tied_Hands = who_Wins(Sorted_Hands)
Tied_Hands.sort(key=lambda x: x[1], reverse=True)
print Tied_Hands
for i in range(len(Tied_Hands)):
vals = [val for (val,suit) in All_Players[Tied_Hands[i][0]]]
print 'vals',sorted(vals,reverse=True)
#for hands in Tied_Hands:
# if
print Tied_Hands[0][0]