Contract Bridge is a card game where players must bid how many tricks they will win at the start of the play. To do this, players evaluate their hands and assign a point value to the hand.

For this assignment you will read in a representation of a bridge hand, evaluate the point value, and print out how many points are in the hand.

A bridge hand is made up of 13 cards. Each card has a face value, represented as one of the character sequences A,2,3,4,5,6,7,8,9,10,J,Q,K; and a suit, represented by one of the characters C D H S. So, for example, the nine of clubs is represented as 9C.

The input to the program will be strings representing cards. Each card is a face value separated from the other by a comma, spaces or newlines. When the input contains a single line containing nothing but a dot character, this indicates that the input of this hand is complete.

Once you read a hand in, you must apply following rules to calculate the point value for hand:

  • Each Ace (A) is worth 4 points
  • Each King (K) is worth 3 points
  • Each Queen (Q) is worth 2 points
  • Each Jack (J) is worth 1 point
  • If the hand contains no aces, subtract 1 point
  • If the hand contains four aces, add 1 point
  • If the hand contains only one king, queen or jack, subtract 1 point
  • For each suit with more than 4 cards in it, add 1 point for each card past 4 cards
  • For each suit with zero cards in it, add 3 points
  • For each suit with one card in it, add 2 points
  • For each suit with two cards in it, add 1 point

When you calculate the resulting points, you should print out, on a line by itself: HAND x TOTAL POINTS y

Where x is an integer indicating the hand that was read in (the first hand is 1, the second is 2, etc.), and y is the points that you calculated for the hand.

Your program will read the standard input for a hand. When the input of the hand is complete, your program should validate that the hand is correct, calculate the points, print the result, and read the standard input for the next hand.

A hand is correct if and only if it has 13 correctly formatted unique cards in it. If any of the cards is incorrectly formatted, the program should print BAD FORMAT. If the count of cards is wrong, the program should print WRONG NUMBER OF CARDS. If there are duplicate cards in the hand, the program should print DUPLICATE CARDS. In these error cases, the program should continue reading the standard input for the next hand after it prints the error message.

Your program should terminate on end-of-file.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.