In this programming assignment you will simulate a regular Poker game otherwise
ID: 3756101 • Letter: I
Question
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 CardExplanation / Answer
# 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): for i in range (len(hand) - 1): if (hand[i].rank == hand[i + 1].rank): 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 < 2) or (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()Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.