Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part V: War Variant #1: Suit Rank (20 points) Complete the function play with su

ID: 3716427 • Letter: P

Question

Part V: War Variant #1: Suit Rank (20 points) Complete the function play with suits (), which takes two arguments, in this order: 1. player 1: a Player object that represents Player #1 2. player2: a Player object that represents Player #2 This function provides an alternate form of gameplay to the rules implemented in the play normal round () function. Rather than decide the winner using card ranks, the winner is decided using suits 1. Hearts beat Spades and Diamonds CSE 101 - Spring 2018 Homework #5 Page 4 2. Spades beat Diamonds and Clubs 3. Diamonds beat Clubs 4. Clubs beat Hearts Here's an example: Player 1 drew 6 Player 2 drew 24 Player 2 won the round, scoring 2 points. Wars are now caused when two cards of the same suit are drawn, as in the example below: Player 1 drew Q* Player 2 drew 8* WAR! Player 1 drew Kt* Player 2 drew 9** WAR! Player 1 drew A Player 2 drew 8 Player 1 won the round, scorinq 6 points.

Explanation / Answer

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)

def game_status(cards_on_table):

    ans = ''

   

    # loop through cards_on_table

    for i in range(0, len(cards_on_table)):

       

        ans += 'Player ' + str(i + 1) + ': ' + cards_on_table[i].rank_sym[cards_on_table[i].rank] + str(cards_on_table[i].suit_sym[cards_on_table[i].suit])

       

        if(i != len(cards_on_table) - 1):

            ans += ' '

    return ans

cards_on_table = [Card(0, 2), Card(0, 3), Card(0, 0), Card(0, 1)]

print(game_status(cards_on_table))