Question: NEEDS TO BE IN PYTHON TEMPLATE: import random class Card (object): RANKS = (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,

 NEEDS TO BE IN PYTHON NEEDS TO BE IN PYTHON TEMPLATE: import random class Card (object): TEMPLATE: import random class Card (object): RANKS = (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) SUITS = ('C', 'D', 'H', 'S') # constructor def __init__ (self, rank = 12, suit = 'S'): if (rank in Card.RANKS): self.rank = rank else: self.rank = 12 if (suit in Card.SUITS): self.suit = suit else: self.suit = 'S' # string representation of a Card object def __str__ (self): if (self.rank == 14): rank = 'A' elif (self.rank == 13): rank = 'K' elif (self.rank == 12): rank = 'Q' elif (self.rank == 11): rank = 'J' else: rank = str (self.rank) return rank + self.suit # equality tests def __eq__ (self, other): return self.rank == other.rank def __ne__ (self, other): return self.rank != other.rank def __lt__ (self, other): return self.rank  other.rank def __ge__ (self, other): return self.rank >= other.rank class Deck (object): # constructor def __init__ (self, n = 1): self.deck = [] for i in range (n): for suit in Card.SUITS: for rank in Card.RANKS: card = Card (rank, suit) self.deck.append (card) # shuffle the deck def shuffle (self): random.shuffle (self.deck) # deal a card def deal (self): if (len(self.deck) == 0): return None else: return self.deck.pop(0) class Poker (object): def __init__ (self, num_players = 2, num_cards = 5): self.deck = Deck() self.deck.shuffle() self.all_hands = [] self.numCards_in_Hand = num_cards # deal all the hands for i in range (num_players): hand = [] for j in range (self.numCards_in_Hand): hand.append (self.deck.deal()) self.all_hands.append (hand) # simulates the play of the game def play (self): # sort the hands of each player and print for i in range (len(self.all_hands)): sorted_hand = sorted (self.all_hands[i], reverse = True) self.all_hands[i] = sorted_hand hand_str = '' for card in sorted_hand: hand_str = hand_str + str(card) + ' ' print ('Player ' + str(i + 1) + ' : ' + hand_str) # determine the type of each hand and print points_hand = [] # create a list to store points for each hand # determine winner and print # determine if a hand is a royal flush # takes as argument a list of 5 Card objects # returns a number (points) for that hand def is_royal (self, hand): same_suit = True for i in range (len(hand) - 1): same_suit = same_suit and (hand[i].suit == hand[i + 1].suit) if (not same_suit): return 0 rank_order = True for i in range (len(hand)): rank_order = rank_order and (hand[i].rank == 14 - i) if (not rank_order): return 0 points = 10 * 15 ** 5 + (hand[0].rank) * 15 ** 4 + (hand[1].rank) * 15 ** 3 points = points + (hand[2].rank) * 15 ** 2 + (hand[3].rank) * 15 ** 1 points = points + (hand[4].rank) return points ''' def is_straight_flush (self, hand): ... def is_four_kind (self, hand): ... def is_full_house (self, hand): ... def is_flush (self, hand): ... def is_straight (self, hand): ... def is_three_kind (self, hand): ... def is_two_pair (self, hand): ... ''' # determine if a hand is one pair # takes as argument a list of 5 Card objects # returns a number (points) for that hand def is_one_pair (self, hand): one_pair = False for i in range (len(hand) - 1): if (hand[i].rank == hand[i + 1].rank): one_pair = True break if (not one_pair): return 0 points = 2 * 15 ** 5 + (hand[0].rank) * 15 ** 4 + (hand[1].rank) * 15 ** 3 points = points + (hand[2].rank) * 15 ** 2 + (hand[3].rank) * 15 ** 1 points = points + (hand[4].rank) return points ''' def is_high_card (self, hand): ... ''' def main(): # prompt the user to enter the number of players num_players = int (input ('Enter number of players: ')) while ((num_players  6)): num_players = int (input ('Enter number of players: ')) # create the Poker object game = Poker (num_players) # play the game - poker game.play() # do not remove this line above main() if __name__ == '__main__': main() 

In this programming assignment you will simulate a regular Poker game otherwise known as the 5-Card Draw. Regular Poker is played with a standard deck of 52 cards. Cards are ranked from high to low in the following order: Ace, King, Queen, Jack, 10,9,8,7,6,5,4,3,2. The value of an Ace is higher than a King which is higher than a Queen and so on. There are four suits - Spades, Hearts, Clubs, and Diamonds. The suits are of equal value Rules of the Game Each player is dealt five cards. The player with the highest valued hand wins. The best to worst hands are ranked in the following order: 1. Royal Flush 2. Straight Flush 3. Four of a Kind 4. Full House 5. Flush 6. Straight 7. Three of a Kind 8. Two Pair 9. One Pair 10. High Card

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!