Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python Preliminaries: import random class Card: suit_sym = {0: 'u2663' , 1: 'u2666' , 2: 'u2665' , 3: 'u2660' } rank_sym = {0: '2' ,
Python
Preliminaries:
import random class Card: suit_sym = {0: '\u2663', 1: '\u2666', 2: '\u2665', 3: '\u2660'} rank_sym = {0: '2', 1: '3', 2: '4', 3: '5', 4: '6', 5: '7', 6: '8', 7: '9', 8: '10', 9: 'J', 10: 'Q', 11: 'K', 12: 'A'} def __init__(self, rank, suit): self.rank = rank self.suit = suit def __repr__(self): return self.rank_sym[self.rank] + self.suit_sym[self.suit] def __eq__(self, other): return self.suit == other.suit and self.rank == other.rank class Player: def __init__(self, card_list): self.card_list = card_list self.score = 0 def __repr__(self): return 'cards: ' + str(self.card_list) + ', score: ' + str(self.score) # Utility function to help with testing. Don't change this function. def build_deck(): card_list = [] for i in range(4): for j in range(13): card_list.append(Card(j, i)) return card_list # Utility function to help with testing. Don't change this function. def build_players(): player_list = [] for i in range(4): player = Player([]) player_list.append(player) return player_listPart II: Taking a Turn (20 points) Write a function take.turn ) that takes the following arguments, in this order: 2. player: A Player object. The function finds the Card object with the highest rank that matches the current.suit from the card.list that the player has, removes that card from the player's card list, and returns the Card object Special Cases: If current.suit is None, find and remove the Card object with the highest rank and return it If there is no Card object in the player's card list that matches the current.suit, find and remove the Card object with the lowest rank and return it. For the two special cases above, if two or more cards in the player's card list have same (highest or lowest) rank, return whichever Card object with same rank appears earliest in the card list for that player object. Example #1: player . card-list- [2, 2 , 3 , 4 , 5 , 6 ] player.card.list[Card (0, 2), Card (0, 1, Card(1, 1), Card (2, 1), Card (3, 1) Card (4, 1)] result - take.turn (*, player)) Return Value: 2 Updated player.card.list: Card (0, 1), Card(1, 1), Card (2, 1), Card (3, 1), Card (4, 1)1 playe r . card-list is now [29 , 3 , 4 , 59 , 6 ]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started