CIT 590 Assignment 7: Hearts
Spring 2010, David Matuszek
Play a game of Hearts. Give the user the choice of being one of the players, or just watching the game.
As with most card games, there are many variations, so be sure to follow the rules as given here.
A deck of cards consists of 52 cards--13 each in four different suits. The
four suits are called Spades, Hearts, Diamonds, and Clubs. Each card in a suit
has a number or a name. The cards are called, from lowest-ranking to highest-ranking,
There are four
of the players, the
Dealer, has extra actions ("shuffling"
and "dealing") that she may take; otherwise, the dealer is just like
the other players. One of the other players may (or may not) be the
Human user. The dealer is always one of the computer players.
Here's how it goes:
Thirteen "tricks" are played. Each trick proceeds as follows:
After doing the above 13 times, all cards have been played and the hand ends. Then the hands are scored.
Hearts count 1 penalty point each, and the Queen of Spades counts as 13 penaltypoints. The goal of the game is to take as few penalty points as possible, that is, try not to take Hearts, and especially try to avoid the Queen of Spades. However, there is one exception: If a player takes all the Hearts and the Queen of Spades, then that player gets no extra points, and all the other players get 26 points each; this is called "shooting the moon", and is a very good thing to do.
The game ends when some player has scored 100 or more penalty points.
After the cards are shuffled and dealt:
Since the first card played was a Diamond, each of the other three players must play a Diamond, if possible. The highest-ranking Diamond played (in this example, the Jack) will take the trick.
This assignment will be much less structured than the previous assignments. I will specify some classes that you should have, and you may have additional classes. It is up to you to figure out what the responsibilities (methods) of each class will be. Those classes are:
Hearts(object)to represent the entire game. Creating a
Heartsobject should start the game.
Card(object)to represent a single playing card,
Player(object)to represent a single player,
Dealer(Player)to represent the particular Player that shuffles and deals the cards, and
Human(Player)to represent the user of the program. If the user decides to just watch, and not play, then there is no reason to create an object of this type.
I will impose one additional requirement. No object should directly examine or alter the variables of any other object; all access should be done by talking to (calling methods of) the other object.
Figure out what the various classes and objects should be, and what their instance variables and their methods should be. There is no single "correct" design; any reasonable design will do. However, we may take off points for really bad design. The better your design, the easier your programming will be.
Use the objects you define to play a game of Hearts. Your computer players must play cards legally, but they do not need to play well. If you want to make the computer players "smart," do it after you hand in the assignment!
Try hard to separate your methods into those that do input/output (and no computation), and those that do computation (and no input/output). Write unit tests for the latter.
Print out everything that happens during the course of a game: Who leads, who plays which cards, who takes each trick, who wins the game, etc.
Before you turn in this assignment, ask a friend or fellow classmate, not your partner, to try out your game. Watch to see if there is anything they don't understand about what to do. If something isn't obvious to them, it probably won't be obvious to the person who grades your program, and that will cost you points.
Unit test all the computational methods. Don't test the methods that do (only) input/output.
All methods should have a comment telling what the method does, even if you think it's obvious. In addition, each method should include the name of the person who wrote it (which may be both of you).
Thursday, March 4, by midnight. Zip together all the relevant files and submit them via Blackboard.