Hi all, I'm trying to make a Poker program. This is what I have so far but I'm not sure how I can check to see if the deck is a Royal Flush, Straight, etc. Could anyone help me get started? This is what my output should be.
Enter the number of hands to play: 3
Hand 1: 9D 9H 6C 3S 8C
Hand 2: AS 2C 8H JD 4S
Hand 3: 3C 7D 5S 6H 4H
Hand 1: Two Pair
Hand 2: High Card
Hand 3: Straight
Hand 3 wins.
class Card (object):
RANKS = (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)
SUITS = ('S', 'D', 'H', 'C')
def __init__ (self, rank, suit):
self.rank = rank
self.suit = suit
def __str__ (self):
if self.rank == 11:
rank = 'J'
elif self.rank == 12:
rank = 'Q'
elif self.rank == 13:
rank = 'K'
elif self.rank == 14:
rank = 'A'
else:
rank = self.rank
return str(rank) + self.suit
import random
class Deck(object):
""" A deck containing 52 cards."""
def __init__(self):
"""Creates a full deck of cards."""
self._cards = []
for suit in Card.SUITS:
for rank in Card.RANKS:
c = Card(rank, suit)
self._cards.append(c)
def shuffle(self):
"""Shuffles the cards."""
random.shuffle(self._cards)
def deal(self):
"""Removes and returns the top card or None
if the deck is empty."""
if len(self) == 0:
return None
else:
return self._cards.pop(0)
def __len__(self):
"""Returns the number of cards left in the deck."""
return len(self._cards)
def __str__(self):
"""Returns the string representation of a deck."""
self.result = ''
for c in self._cards:
self.result = self.result + str(c) + '\n'
return self.result
class Poker (object):
def __init__ (self, numHands):
self.deck = Deck()
self.deck.shuffle()
self.hands = []
numCards_in_Hand = 5
for i in range (numHands):
hand = []
for j in range (numCards_in_Hand):
hand.append (self.deck.deal())
self.hands.append (hand)
def isRoyal (self, hand):
...
def isStraight (self, hand):
...
def isFour (self, hand):
...
def isFull (self, hand):
...
def isFlush (self, hand):
...
def isStraight (self, hand):
...
def isThree (self, hand):
...
def isTwo (self, hand):
...
def isOne (self, hand):
...
def isHigh (self, hand):
...
def main():
cond = True
while (cond):
numHands = input("Enter the number of hands to play: ")
cond = numHands <= 2 and numHands >= 6
main()