Question
Python 3 You will be working with the following classes that represent a playing card and a player: class Card: suit_sym = {0: u2663, 1:
Python 3
You will be working with the following classes that represent a playing card and a player:
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)
Data Encoding for the suit Field in the Card Class
0 represents Clubs
1 represents Diamonds
2 represents Hearts
3 represents Spades
Data Encoding for the rank Field in the Card Class
0 represents 2
1 represents 3
.
.
.
11 represents K
12 represents A
Additional Functionality
In the homework5.py file you will find the typical main if-statement, but also two functions: run tests()
and simulate game(). Inside the main section (at the very end of the file) you will see that the run tests()
function is called, but simulate game() is commented out. The run tests() will execute the same test
cases given in the PDF. The simulate game() function will call the functions you must write to simulate
a full 13-round game of Bridge. Although you dont have to use the simulate game() to test your work,
you may find it useful/interesting to watch a game played out from start to finish. Realistically, however, the
simulate game() will crash the program until you have implemented most of the required functions.
You will be required to write the following five functions (not methods) to support playing of the game.
Write a function deal.cards that takes the following arguments, in this order: 1. player.list: A list of 4 Player objects. 2. card.list: A list of 52 Card objects. Your function should deal each Card object in card.list to each Player in player.list in the following order 1. The first Card object in the card.list list is added to first Player object in player.list list. 2. The second Card object in the card.list list is added to second Player object in player.list list . The third Card object in the card.list list is added to third Player object in player.list list. 4. The fourth Card object in the card.list list is added to fourth Player object in player.list list. 5The fifth Card object in the card-list list is added to first Player object in player-list list and so on, up until the last Card object from card.list has been dealt. This function doesn't return any values. Example: Suppose card.list contained the following cards, in this order: The cards would be distributed to the players as follows Write a function deal.cards that takes the following arguments, in this order: 1. player.list: A list of 4 Player objects. 2. card.list: A list of 52 Card objects. Your function should deal each Card object in card.list to each Player in player.list in the following order 1. The first Card object in the card.list list is added to first Player object in player.list list. 2. The second Card object in the card.list list is added to second Player object in player.list list . The third Card object in the card.list list is added to third Player object in player.list list. 4. The fourth Card object in the card.list list is added to fourth Player object in player.list list. 5The fifth Card object in the card-list list is added to first Player object in player-list list and so on, up until the last Card object from card.list has been dealt. This function doesn't return any values. Example: Suppose card.list contained the following cards, in this order: The cards would be distributed to the players as followsStep 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