Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# Part I def create_deck(): deck = [] for i in range(4): for j in range(13): deck.append(Card(j, i)) return deck # Part II def deal_cards(deck):

image text in transcribed

image text in transcribed

# Part I  def create_deck(): deck = [] for i in range(4): for j in range(13): deck.append(Card(j, i)) return deck # Part II def deal_cards(deck): cards1=[] cards2=[] for index in range(0,len(deck),2): cards1.append(deck[index]) if index+1return player1 , player2

War Classes:

# Initialize card data CLUBS = u'\u2663' SPADES = u'\u2660' DIAMONDS = u'\u2666' HEARTS = u'\u2665' suits = {0: CLUBS, 1: SPADES, 2: DIAMONDS, 3: HEARTS} ranks = {k: k + 2 for k in range(9)} # maps 0->2, 1->3, ..., 8:10 ranks[9] = 'J' ranks[10] = 'Q' ranks[11] = 'K' ranks[12] = 'A'  print_output = False  # DO NOT CHANGE THE CONTENTS OF THIS FILE # # DO NOT CHANGE THE CONTENTS OF THIS FILE # # DO NOT CHANGE THE CONTENTS OF THIS FILE #  class Card: def __init__(self, rank, suit): self._rank = rank self._suit = suit def __str__(self): return str(ranks[self._rank]) + str(suits[self._suit]) def __repr__(self): return self.__str__() def __eq__(self, other): return self._rank == other._rank and self._suit == other._suit # DO NOT CHANGE THE CONTENTS OF THIS FILE # # DO NOT CHANGE THE CONTENTS OF THIS FILE # # DO NOT CHANGE THE CONTENTS OF THIS FILE #  class Player: def __init__(self, player_num, score, cards): self._player_num = player_num self._score = score self._cards = cards def __str__(self): return 'Player(' + str(self._player_num) + ',' + str(self._score) + ',' + \ str(self._cards) + ')'   def __repr__(self): return self.__str__() def __eq__(self, other): return self._player_num == other._player_num and self._score == other._score and \ self._cards == other._cards def draw_card(self): card = self._cards.pop(0) if print_output: print('Player', self._player_num, 'drew', card) return card # DO NOT CHANGE THE CONTENTS OF THIS FILE # # DO NOT CHANGE THE CONTENTS OF THIS FILE # # DO NOT CHANGE THE CONTENTS OF THIS FILE # 

python please

Part III: Play One Round (20 points) Complete the function play-normalround ), which takes twos arguments, in this order: 1. player 1: a Player object that represents Player #1 2 player 2: a p laye r object that represents Player #2 Each Player object has equal number of Card objects in its.cards attribute. The function draws cards from each player's hand (use the draw-card) method in the Player class) until a player wins the round or the players run out of cards. Here is an example of how you might have Player #1 draw a card player1_card-player1.draw_card() lf, on the first draw, the rank of Player #l's card is greater than the rank of Player #2's card, then Player #1 wins the round and the function returns the tuple ( 1, 2 ) , where l indicates Player #1 and 2 indicates the points won by the player. The function also adds 2 to player 1.-score. As in the real War card game, Player #1 earns 2 points because he "wins, two cards: his own, as well as Player #2's card. The cards are discarded and are not added to either player's card list. Similarly, if the rank of Player #2's card is greater than the rank of Player #1's card, then Player #2 wins the round and the function returns the tuple (2, 2) . The function also adds 2 to player2..score. Here is an example: Part III: Play One Round (20 points) Complete the function play-normalround ), which takes twos arguments, in this order: 1. player 1: a Player object that represents Player #1 2 player 2: a p laye r object that represents Player #2 Each Player object has equal number of Card objects in its.cards attribute. The function draws cards from each player's hand (use the draw-card) method in the Player class) until a player wins the round or the players run out of cards. Here is an example of how you might have Player #1 draw a card player1_card-player1.draw_card() lf, on the first draw, the rank of Player #l's card is greater than the rank of Player #2's card, then Player #1 wins the round and the function returns the tuple ( 1, 2 ) , where l indicates Player #1 and 2 indicates the points won by the player. The function also adds 2 to player 1.-score. As in the real War card game, Player #1 earns 2 points because he "wins, two cards: his own, as well as Player #2's card. The cards are discarded and are not added to either player's card list. Similarly, if the rank of Player #2's card is greater than the rank of Player #1's card, then Player #2 wins the round and the function returns the tuple (2, 2) . The function also adds 2 to player2..score. Here is an example

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions