| CPSC 115L: Introduction to Computing | Fall2010 |
For this assignment we will write a program that deals one hand of bridge to a table of four players named North, East, South, West. Let's suppose that West is the dealer of this hand. West would deal one card to North, then one to East, then one to South, then one to West. This would be repeated 13 times, until all 52 cards have been dealt.
Following the deal, print the contents of each hand, North to West, and their respective point totals, as shown here:
North ( 8 ): 3C, 4C, 7C, 8C, 10C, JC, AC, 10D, 3H, 5H, 9H, QH, JS East ( 21 ): QC, 9D, QD, 4H, 7H, 10H, JH, KH, AH, 10S, QS, KS, AS South ( 1 ): 2C, 5C, 3D, 4D, 5D, 6D, 7D, JD, 2H, 6H, 8H, 2S, 6S West ( 10 ): 6C, 9C, KC, 2D, 8D, KD, AD, 3S, 4S, 5S, 7S, 8S, 9S
Note how the cards are arranged in each hand, first all the Clubs, from lowest to highest, then all the Diamonds, Hearts, and Spades. This is the required order for Bridge.
In bridge, the point value of a hand is used to help players decide how to bid. We aren't going to go into the bidding and playing of a hand. That would be too complicated. But just reporting an accurate count is an interesting problem and provides a useful example of how to use object-oriented programming and inheritance in Python.
Here's how points are counted in Bridge. Aces are worth 4 points, Kings 3, Queens 2, and Jacks 1. The other cards have no point value. Bridge hands can receive various bonus points -- e.g., 3 points for null suit, bonus points for Ace, King, Queen, Jack, etc. -- but we aren't going to worry about that for this assignment.
For each of the following problems you will be defining new classes and methods and writing code segments (Python scripts) to test your definitions and to perform tasks such as dealing a hand a bridge. The scripts should go at the end of your file, after all of the class and method definitions.
Download into your Lab 10 folder cards.py module. This file includes definitions of the Card, Deck, and Hand classes. Open and read the definitions of the Card, Deck, and Hand classes. You will need to use them in your program. You may want to print a copy of this file so you can easily refer to it during the lab. You may not modify the Card, Deck, and Hand classes in any way.
Create a new file named bridge.py for your Bridge program and place the following import statement at the beginning of this file (after the comment block):
from cards import Card, Deck, Hand
This statement imports all of the definitions from cards.py allowing you to use them in your code.
card1 = BridgeCard(2,3) # 3H 3 of Hearts card2 = BridgeCard(0, 11) # JC Jack of Clubs card3 = BridgeCard(3,12) # KS King of Spades card4 = BridgeCard(3,13) # AS Ace of spaces
This problem deals with subclassing the Deck class.
2C, 3C, 4C, 5C, 6C, 7C, 8C, 9C, 10C, JC, QC, KC, AC, 2D, 3D, 4D, 5D, 6D, 7D, 8D, ... KD, 2S, 8H, 7S, 5H, QD, 10D, 10H, QC, AC, 3S, 9D, 5D, 10C, 8D, 8S, 6C, 6H, 5C, 9H, ... 2C, 3C, 4C, 5C, 6C, 7C, 8C, 9C, 10C, JC, QC, KC, AC, 2D, 3D, 4D, 5D, 6D, 7D, 8D, ...
In this problem we will subclass the Hand class.
Done dealing, deck = North : 6C, QC, 5D, 8D, 10D, JD, AD, 3H, 4H, 5H, 6H, AH, 5S East : 7C, AC, 4D, 7D, QD, 8H, JH, QH, KH, 2S, 3S, 4S, 8S South : 2C, 5C, JC, KC, 2D, 3D, 9D, 2H, 9H, 10H, 6S, 7S, 10S West : 3C, 4C, 8C, 9C, 10C, 6D, KD, 7H, 9S, JS, QS, KS, AS
This exercise will deal with calculate the points value of a bridge hand.
Done dealing, deck = North ( 5 ): 3C, 6C, 7D, 8D, 10D, AD, 6H, 8H, 9H, 10H, JH, 3S, 10S East ( 12 ): 8C, 9C, KC, 2D, 3H, 5H, 7H, 4S, 5S, 9S, QS, KS, AS South ( 8 ): 2C, 5C, 10C, 3D, 4D, 9D, JD, QD, 4H, AH, 6S, 8S, JS West ( 15 ): 4C, 7C, JC, QC, AC, 5D, 6D, KD, 2H, QH, KH, 2S, 7S
Done dealing, deck = North ( 5 ): 3C, 6C, 7D, 8D, 10D, AD, 6H, 8H, 9H, 10H, JH, 3S, 10S East ( 12 ): 8C, 9C, KC, 2D, 3H, 5H, 7H, 4S, 5S, 9S, QS, KS, AS South ( 8 ): 2C, 5C, 10C, 3D, 4D, 9D, JD, QD, 4H, AH, 6S, 8S, JS West ( 15 ): 4C, 7C, JC, QC, AC, 5D, 6D, KD, 2H, QH, KH, 2S, 7S The high hand is West ( 15 ): 4C, 7C, JC, QC, AC, 5D, 6D, KD, 2H, QH, KH, 2S, 7S
|
|
CPSC 115L home page |
|
|