Problem 2: The Lambda-ing (350pts)

In the next part of this homework, we will be implementing a card game!

You can start the game by typing:

python cardgame.py

This game doesn't work yet. If we run this right now, the code will error, since we haven't implemented anything yet. When it's working, you can exit the game and return to the command line with Ctrl-C or Ctrl-D.

This game uses several different files.

  • Code for all the questions in this homework can be found in hw06.py.
  • Some utility for the game can be found in cardgame.py, but you won't need to open or read this file. This file doesn't actually mutate any instances directly - instead, it calls methods of the different classes, maintaining a strict abstraction barrier.
  • If you want to modify your game later to add your own custom cards and decks, you can look in cards.py to see all the standard cards and the default deck; here, you can add more cards and change what decks you and your opponent use. The cards were not created with balance in mind, so feel free to modify the stats and add/remove cards as desired.

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 Professor 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.
  • 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!