Question: class Player(object): def __init__(self, deck, name): Initialize a Player object. A Player starts the game by drawing 5 cards from their deck. Each turn, a

class Player(object):

def __init__(self, deck, name):

"""Initialize a Player object.

A Player starts the game by drawing 5 cards from their deck. Each turn,

a Player draws another card from the deck and chooses one to play.

>>> test_card = Card('test', 100, 100)

>>> test_deck = Deck([test_card.copy() for _ in range(6)])

>>> test_player = Player(test_deck, 'tester')

>>> len(test_deck.cards)

1

>>> len(test_player.hand)

5

"""

self.deck = deck

self.name = name

"*** YOUR CODE HERE ***"

def draw(self):

"""Draw a card from the player's deck and add it to their hand.

>>> test_card = Card('test', 100, 100)

>>> test_deck = Deck([test_card.copy() for _ in range(6)])

>>> test_player = Player(test_deck, 'tester')

>>> test_player.draw()

>>> len(test_deck.cards)

0

>>> len(test_player.hand)

6

"""

assert not self.deck.is_empty(), 'Deck is empty!'

"*** YOUR CODE HERE ***"

Rules of the Game
This game is a little involved, though not nearly as much as its namesake. Here's how it goes:
There are two players. Each player has a hand of cards and a deck, and at the start of each round, each player draws a card from their deck. If a player's deck is empty when they try to draw, they will automatically lose the game. Cards have a name, an attack stat, and a defense stat. Each round, each player chooses one card to play from their own hands. The card with the higher power wins the round. Each played card's power value is calculated as follows:
(player card's attack) - (opponent card's defense) / 2
For example, let's say Player 1 plays a card with 2000 ATK/1000 DEF and Player 2 plays a card with 1500 ATK/3000 DEF. Their cards' powers are calculated as:
P1: 2000 - 3000/2 = 2000 - 1500 = 500
P2: 1500 - 1000/2 = 1500 - 500 = 1000
so Player 2 would win this round.
The first player to win 8 rounds wins the match!
However, there are a few effects we can add (in the optional questions section) to make this game a bit more interesting. Cards are split into Tutor, TA, and Instructor types, and each type has a different effect when they're played. All effects are applied before power is calculated during that round:
A Tutor will cause the opponent to discard and re-draw the first 3 cards in their hand.
A TA will swap the opponent card's attack and defense.
An Instructor will add 300 attack and defense to all cards in the player's deck, and then add a copy of the opponent's card to both the player's deck and the player's hand.
A Professor adds the opponent card's attack and defense to all cards in their deck and then remove all cards in the opponent's deck that share its attack or defense!
These are a lot of rules to remember, so refer back here if you need to review them, and let's start making the game!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!