I'm attempting to create 5 card stud poker game, I'm almost in the final step of it but I am not understanding how to implement it.

Evaluate each players hand to determine winner(This is where my difficulty reside at the moment)

Sorry if the code is messy and long, still getting used to all this. I would appreciate any input.

This is what i have so far...

```
import random
deck = [ \
'2c' , '3c' , '4c' , '5c' , '6c' , '7c' , '8c' , '9c' , '10c' , 'Jc' , 'Qc' , 'Kc', 'Ac', \
'2h' , '3h' , '4h' , '5h' , '6h' , '7h' , '8h' , '9h' , '10h' , 'Jh' , 'Qh' , 'Kh' , 'Ah', \
'2s' , '3s' , '4s' , '5s' , '6s' , '7s' , '8s' , '9s' , '10s' , 'Js' , 'Qs' , 'Ks' , 'As', \
'2d' , '3d' , '4d' , '5d' , '6d' , '7d' , '8d' , '9d' , '10d' , 'Jd' , 'Qd' , 'Kd' , 'Ad' ]
def sortRank(hand):
ranks = list()
for card in hand:
if len(card) == 3:
ranks.append(10)
elif card[0] == 'J':
ranks.append(11)
elif card[0] == 'Q':
ranks.append(12)
elif card[0] == 'K':
ranks.append(13)
elif card[0] == 'A':
ranks.append(14)
else:
ranks.append(int(card[0]))
for i in range(4):
for j in range(i+1, 5):
if ranks[j] > ranks:
temp = hand
tempR = ranks
hand = hand[j]
ranks = ranks[j]
hand[j] = temp
ranks[j] = tempR
return hand
def sortSuit(hand):
ranks = list()
for card in hand:
if card[1] == 'h' or (card[1] == '0' and card[2] == 'h' ):
addval = 26
elif card[1] == 's' or (card[1] == '0' and card[2] == 's' ):
addval = 13
elif card[1] == 'd' or (card[1] == '0' and card[2] == 'd' ):
addval = 0
else:
addval = 39
if len(card) == 3:
ranks.append(10 + addval)
elif card[0] == 'J':
ranks.append(11 + addval)
elif card[0] == 'Q':
ranks.append(12 + addval)
elif card[0] == 'K':
ranks.append(13 + addval)
elif card[0] == 'A':
ranks.append(14 + addval)
else:
ranks.append(int(card[0]) + addval)
for i in range(4):
for j in range(i+1, 5):
if ranks[j] > ranks:
temp = hand
tempR = ranks
hand = hand[j]
ranks = ranks[j]
hand[j] = temp
ranks[j] = tempR
return hand
def numRank(hand):
ranks = list()
for card in hand:
if len(card) == 3:
ranks.append(10)
elif card[0] == 'J':
ranks.append(11)
elif card[0] == 'Q':
ranks.append(12)
elif card[0] == 'K':
ranks.append(13)
elif card[0] == 'A':
ranks.append(14)
else:
ranks.append(int(card[0]))
return ranks
def numSuit(hand):
ranks = list()
for card in hand:
if card[1] == 'h' or (card[1] == '0' and card[2] == 'h' ):
addval = 26
elif card[1] == 's' or (card[1] == '0' and card[2] == 's' ):
addval = 13
elif card[1] == 'd' or (card[1] == '0' and card[2] == 'd' ):
addval = 0
else:
addval = 39
ranks.append(addval)
return ranks
def setDealt(nbrhands):
sets=list()
while len(sets) < nbrhands:
sets.append(list())
return sets
def shuffle(nbrhands):
random.shuffle(deck)
return deck
def dealHands(nbrhands):
setsofHands=setDealt(nbrhands)
shuffledDeck=shuffle(nbrhands)
for i in range(nbrhands):
setsofHands.append(shuffledDeck[0])
shuffledDeck.remove(shuffledDeck[0])
for i in range(nbrhands):
setsofHands.append(shuffledDeck[0])
shuffledDeck.remove(shuffledDeck[0])
for i in range(nbrhands):
setsofHands.append(shuffledDeck[0])
shuffledDeck.remove(shuffledDeck[0])
for i in range(nbrhands):
setsofHands.append(shuffledDeck[0])
shuffledDeck.remove(shuffledDeck[0])
for i in range(nbrhands):
setsofHands.append(shuffledDeck[0])
shuffledDeck.remove(shuffledDeck[0])
return setsofHands
def royalFlush(hand):
sorthand=sortRank(hand)
if sorthand == ['Ad', 'Kd', 'Qd', 'Jd', '10d']:
return True
elif sorthand == ['Ac', 'Kc', 'Qc', 'Jc', '10c']:
return True
elif sorthand == ['Ah', 'Kh', 'Qh', 'Jh', '10h']:
return True
elif sorthand == ['As', 'Ks', 'Qs', 'Js', '10s']:
return True
else:
return False
def straightFlush(hand):
numrank=numRank(sortRank(hand))
numsuit=numSuit(sortSuit(hand))
if numsuit[0]==numsuit[1]==numsuit[2]==numsuit[3]==numsuit[4]:
if numrank[0]==numrank[1]+1==numrank[2]+2==numrank[3]+3==numrank[4]+4:
return True
else:
return False
else:
return False
def fourOfAKind(hand):
numrank=numRank(sortRank(hand))
if numrank[0]==numrank[1]==numrank[2]==numrank[3]:
return True
elif numrank[1]==numrank[2]==numrank[3]==numrank[4]:
return True
else:
return False
def fullHouse(hand):
numrank=numRank(sortRank(hand))
if numrank[0]==numrank[1] and numrank[2]==numrank[3]==numrank[4]:
return True
elif numrank[0]==numrank[1]==numrank[2] and numrank[3]==numrank[4]:
return True
else:
return False
def flush(hand):
numsuit=numSuit(sortSuit(hand))
if numsuit[0]==numsuit[1]==numsuit[2]==numsuit[3]==numsuit[4]:
return True
else:
return False
def straight(hand):
numrank=numRank(sortRank(hand))
if numrank[0]==numrank[1]+1==numrank[2]+2==numrank[3]+3==numrank[4]+4:
return True
else:
return False
def threeOfAKind(hand):
numrank=numRank(sortRank(hand))
if numrank[0]==numrank[1]==numrank[2]:
return True
elif numrank[1]==numrank[2]==numrank[3]:
return True
elif numrank[2]==numrank[3]==numrank[4]:
return True
else:
return False
def twoPair(hand):
numrank=numRank(sortRank(hand))
if numrank[0]==numrank[1] and numrank[2]==numrank[3]:
return True
elif numrank[1]==numrank[2] and numrank[3]==numrank[4]:
return True
elif numrank[0]==numrank[1] and numrank[3]==numrank[4]:
return True
else:
return False
def pair(hand):
numrank=numRank(sortRank(hand))
if numrank[0]==numrank[1]:
return True
elif numrank[1]==numrank[2]:
return True
elif numrank[2]==numrank[3]:
return True
elif numrank[3]==numrank[4]:
return True
else:
return False
def winner(allHands):
checkhand=list()
winnerhand=list()
for i in allHands:
if royalFlush(i)==True:
checkhand.append(i)
if len(checkhand)==0:
for i in allHands:
if straightFlush(i)==True:
checkhand.append(i)
if len(checkhand)==0:
for i in allHands:
if fourOfAKind(i)==True:
checkhand.append(i)
if len(checkhand)==0:
for i in allHands:
if fullHouse(i)==True:
checkhand.append(i)
if len(checkhand)==0:
for i in allHands:
if flush(i)==True:
checkhand.append(i)
if len(checkhand)==0:
for i in allHands:
if straight(i)==True:
checkhand.append(i)
if len(checkhand)==0:
for i in allHands:
if threeOfAKind(i)==True:
checkhand.append(i)
if len(checkhand)==0:
for i in allHands:
if twoPair(i)==True:
checkhand.append(i)
if len(checkhand)==0:
for i in allHands:
if pair(i)==True:
checkhand.append(i)
if len(checkhand)==0:
for i in allHands:
checkhand.append(i)
```