Due: by midnight Monday, October 1, 2012.
Your program listing should have the following information. Note that Poker.py is the top level file. The others merely contain the classes of the same name. They will be imported as necessary into the others.
# Files: Card.py, Deck.py, Hand.py, Poker.py # # Description: # # Student's Name: # # Student's UT EID: # # Course Name: CS 313E # # Date Created: # # Date Last Modified:
Ace of Spades 3 of Diamonds King of Spades 3 of Hearts Ace of HeartsYou can preprocess a hand to extract the information you need as follows. Define two lists:
mysuits = [0] * 4 # a list of 4 zeros myranks = [0] * 13 # a list of 13 zerosFor each card in the hand, extract the suit and rank and increment the appropriate positions in mysuits and myranks. For example, given the hand above, this yields:
# 2 Spades, 1 Diamond, 2 Hearts, no Clubs mysuits: [ 2, 1, 2, 0 ] # 2 Aces, 2 3's, 1 King myranks: [ 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]using the ordering [Spades, Diamonds, Hearts, Clubs] for the suits as defined in the Card class.
Given this information you have:
def evaluateHand(self):
if self.hasRoyalFlush():
return "Royal Flush"
elif self.hasStraightFlush():
return "Straight Flush"
elif self.hasFourOfAKind():
return "Four of a kind"
elif self.hasFullHouse():
return "Full House"
elif self.hasFlush():
return "Flush"
elif self.hasStraight():
return "Straight"
elif self.hasThreeOfAKind():
return "Three of a kind"
elif self.hasTwoPair():
return "Two pair"
elif self.hasPair():
return "Pair"
else:
return "Nothing"
Your driver for the extra credit should allow specify how many "rounds" to play. In each round, deal two hands, evaluate both and say which won, if there's a winner. Your code must do that test using the "<" operator on the two hands. In any round, generate a new deck if there are not 10 cards left in the deck. You wouldn't want to compare two hands dealt from different decks.
felix:~/cs313e/python/Poker> python Poker.py How many hands should I deal? 15 Hand drawn ( 1 ): 9 of Spades Ace of Diamonds 4 of Spades Ace of Spades 3 of Spades Pair Hand drawn ( 2 ): 9 of Clubs 7 of Spades 7 of Diamonds 5 of Hearts Ace of Hearts Pair Hand drawn ( 3 ): Jack of Spades 4 of Diamonds Queen of Diamonds 9 of Diamonds Jack of Clubs Pair Hand drawn ( 4 ): 7 of Hearts 3 of Diamonds 8 of Diamonds King of Spades 3 of Clubs Pair Hand drawn ( 5 ): 5 of Diamonds 5 of Spades 2 of Clubs 9 of Hearts 10 of Spades Pair Hand drawn ( 6 ): 10 of Diamonds 4 of Clubs King of Diamonds Jack of Hearts King of Clubs Pair Hand drawn ( 7 ): 6 of Diamonds 6 of Hearts 10 of Hearts 2 of Hearts 8 of Spades Pair Hand drawn ( 8 ): 2 of Spades 7 of Clubs King of Hearts 8 of Clubs Queen of Hearts Nothing Hand drawn ( 9 ): Ace of Clubs 4 of Hearts Queen of Clubs 8 of Hearts Queen of Spades Pair Hand drawn ( 10 ): 10 of Clubs Jack of Diamonds 6 of Spades 5 of Clubs 6 of Clubs Pair Dealing a new deck. Hand drawn ( 11 ): 6 of Hearts Jack of Clubs 7 of Hearts 9 of Hearts Queen of Clubs Nothing Hand drawn ( 12 ): 10 of Diamonds 2 of Clubs Jack of Spades Ace of Spades 3 of Diamonds Nothing Hand drawn ( 13 ): Jack of Hearts 5 of Spades 10 of Hearts 5 of Hearts Queen of Spades Pair Hand drawn ( 14 ): 3 of Hearts 2 of Spades 10 of Spades Jack of Diamonds 7 of Spades Nothing Hand drawn ( 15 ): 8 of Hearts 8 of Clubs 9 of Spades 7 of Diamonds 4 of Clubs Pair