CIT 590 Assignment 4: A Hand of Bridge
Spring 2009, David Matuszek

Purposes of this assignment:

General idea of the assignment:

Play a hand of bridge.

Don't worry--you don't actually have to know bridge in order to do this assignment. In fact, this assignment is "inspired by" bridge in the same way that a movie is "inspired by" a true story. I'm providing some very simplified rules. If you do know how to play bridge, please accept my apologies--but the assignment is still to write a program to play this version, not the real game.

The rules:

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 from 1 to 13. Hence we have cards such as "the 4 of Spades" or "the 13 of Diamonds." (We do not have Ace, Jack, Queen, King cards, just numbered cards.)

There are four players, whom we will call North, East, South and West. Any player can act as the "dealer."

Here's how it goes:

  1. The dealer "shuffles" the deck. This randomizes the order of the cards, but there are still 52 different cards--no card ever occurs twice.
  2. The dealer "deals" the cards; that is, she gives 13 cards to each player, including herself. The 13 cards held by a player are that player's "hand."
  3. One of the players is chosen (I don't care how) to "lead," that is, to play the very first card.

Next, thirteen "tricks" are played. Each trick proceeds as follows:

  1. The chosen player plays the first card. "Playing a card" means removing it from her hand and letting the other players know which card it is. (In the real game, the card is placed face up on the table.) It is important to notice what the suit of this card is. In this simplified game, any card may be played as the first card of a trick (the players have no strategy or any idea of a "good" card to play).
  2. Each of the remaining players then plays a card. If a player has any cards of the same suit as the first card played, then she must "follow suit" (play a card of the same suit). If she has no cards of the same suit, she may play any card.
  3. When all four players have played a card, the player who played the highest-numbered card of the first suit played "takes the trick"--she collects and puts aside all four cards (we can ignore this bit--you don't need to keep track of the cards after the trick has been played). This player is then chosen to lead (play the first card of) the next trick.

After doing the above 13 times, all cards have been played and the hand ends. The program ends, too.

There is no strategy to this game, it isn't scored, nobody wins or loses. It's a stupid game, OK?

Partial Example (one trick):

After the cards are shuffled and dealt:

  1. North plays the 5 of Hearts
  2. East plays the 8 of Hearts
  3. South (who has no Hearts) plays the 12 of Diamonds
  4. West plays the 1 of Hearts

Since the first card played was a Heart, the player who played the largest Heart (East, with the 8 of Hearts) collects the four cards, and "leads"--chooses any card from her hand (of any suit) to start the next trick. Whatever card East chooses, the other three players must play cards of the same suit, if possible.

Your assignment:

I will suggest what classes you need (and you may have more, if you like), but it's up to you to decide what their instance variables and their methods should be.

Use the objects you define to play a hand of "bridge."

Print out at least:

Structure of the assignment:

The above are requirements. You may have additional classes and methods as needed, and they should be documented and unit tested as appropriate.

Due date:

Thursday, February 12, before midnight. Hand in one project with both your names on it; zip up the entire project directory and hand it in via Blackboard.