Contract Bridge is a card game in which the players bid to see who gets to play first. Although the game itself is quite simple, people have invented some complex rules for how to bid. In this assignment, you will write a program that decides what to bid. This program determines only the first, or "opening" bid; later bids are beyond the scope of this assignment.
You do not need to know how to play Bridge in order to write this program. I will tell you everything you need to know about Bridge. The rules that I give for making the opening bid are basically the system invented by Charles Goren, with minor modifications by others. Understand this: If you know a different set of rules, forget them, because your program will be graded on whether it follows my rules, which are slightly simplified (for instance, I ignore "quick tricks").
There are 52 cards in a Bridge deck. Every card has a value (2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, or Ace) and a suit (Clubs, Diamonds, Hearts, or Spades). The suits are ranked: Clubs < Diamonds < Hearts < Spades (Conveniently, this ordering happens to be the same as alphetical order.) Clubs and Diamonds are the minor suits; Hearts and Spades are the major suits. The Jack, Queen, King, and Ace are called face cards. A hand consists of 13 cards randomly chosen from a deck.
To make it easier to see all thirteen cards in a hand, we will use the following abbreviations: C=Clubs, D=Diamonds, H=Hearts, S=Spades, J=Jack, Q=Queen, K=King, and A=Ace. An individual card will be represented by its value followed by its suit, for example, '6H' represents the 6 of Hearts. For example, a hand might be displayed as.
A bid will be represented by a similar, but not identical, representation; it will be a string consisting of a count 1 to 7, and a trump suit, which may be one of the four suits or the special No Trump bid, abbreviated NT, meaning no particular suit. So some legal bids might be "1S", "5H", or "3NT". For about half the hands there will be no good opening bid, and in these cases your program should return a bid of "Pass", meaning "no bid."
Determining the opening bid proceeds in two stages. First, you need to count the number of points in the hand. Second, you use this point count along with the distribution (how many of each suit there are) to decide the opening bid.
The point count of a hand is the number of high card points, plus the number of distribution points.
High card points: Each Ace counts 4 points; each King counts 3 points; each Queen counts 2 points; and each Jack counts 1 point. For example, the hand given above contains AS, JD, KH, and AD, which is 4+1+3+4=12 points. Non-face cards aren't counted.
Distribution points: If you have more than 4 cards in any suit, count 1 point for each additional card. The sample hand above has 5 Clubs, 3 Diamonds, 4 Hearts, and 1 Spade, so add 1 distribution point for the Clubs, making the total point count 13.
Balance: A hand is balanced if it contains from two to four cards in each suit. As a special case, a hand that has 5 cards in a minor suit (Clubs or Diamonds), with 3, 3, and 2 cards in the other suits, is also considered balanced.
The following is slightly adapted from http://www.cs.cmu.edu/~hde/bidding.htm:
Your program should bid as follows, using the first rule that applies:
1NT: Exactly 16-18 high card points, a balanced hand (4-3-3-3, 4-4-3-2, or 5-3-3-2 where
the 5 cards are in a minor suit).1H or 1S: 13-21 points and 5 or more cards in Hearts or Spades (bid the longer suit; if you have two five-card suits, bid the higher-ranking suit.)
Here's the way it was originally:
|
Here's the corrected version. Rules 3 and 4 have been reversed, and the underlined part in the new rule 4 replaces the crossed-out part.
|
2NT: Exactly 21-23 high card points and a balanced hand (4-3-3-3, 4-4-3-2,
or 5-3-3-2 where the 5 cards are in a minor suit).2H or 2S); otherwise, Pass in all other cases.You must have the following methods in a Bid object.
def highCardPoints(hand: Hand): Intdef distributionPoints(hand: Hand): Intdef pointCount(hand: Hand): Intdef isBalanced(hand: Hand): Booleandef length(suit: String, hand: Hand): Int "Clubs", "Diamonds", "Hearts", or "Spades") in the hand.def openingBid bid(hand: Hand): String1D or 2NT), or Pass. This method should call a number of smaller methods, rather than doing all the work itself. For example, you might have a Boolean method named shouldBidOneNoTrump, with appropriate parameters.We will be running our own unit tests on your program, and if we can't call the above methods and get the right kind of result, you may lose lots of points. So spell the method names correctly, get the capitalization right, and be sure you know what to expect as a parameter and what to return as a result.
You do not need a main method, and you should not do any input or output (except to help you in debugging, then remove it before you submit the program). This isn't a complete program, it's a set of methods that could be used by a bridge playing program.
Note on naming Boolean methods: You should prefer names that sound as if they are asking a yes/no question. A good way to check this is to put them in an if expression: for example, . Often the prefix is or has can be used: , . In the NumberPersonalities assignment, would have sounded okay, but it would have been annoying to try to remember which methods started with is and which did not, so I used is throughout for consistency.
As we have not yet had a chance to cover Vectors in lecture, some code (Bid.scala) has been provided to help you get started. The Card class describes a single playing card; there are 52 objects of this class. There is also a CardDeck object--we only need one card deck object, so there is no reason to describe the class of card decks. The Hand class is a synonym for a built-in Scala class that we have not covered in lecture. Finally, the Bid class contains sample code to show you how to use the other classes; you should throw this code away and replace it with your own.
Pair programming is best done sitting together at one computer. If you can, come in together and work in the lab--or in a lounge, or anyplace you can get together with your partner.
Many of you won't be able to do this after the lab ends. Exchange email addresses, and do your best to share code, read each other's code, and work cooperatively. You probably use some chat program with friends; use it here.
One program that looks like it may be very helpful is Gobby. I haven't recommended this program to classes before, so if you try it, please let me know how it works out. Since it is designed for sharing plain text, I think it may be better for pair programming than, say, Google Docs.
Each program is worth 100 points, unless otherwise specified. Grading will be based on correctness, style, and useability.
.zip file, to Canvas by 6am next Friday, September 20. Decide which of you is going to turn in the assignment, and make only one submission for the two of you. Make sure both of your names are in comments at the top of each file.