CSCI 152                    Program 3

Fall 2005                                                             Due:  Friday, 21 Mar

 

Emphasis on:  Structures and Arrays of Structures

 

You are to write a program which evaluates a bridge hand (dealt to each of four players) by counting the number of points represented in each hand.  The program then displays the hands and the number of points in each.

 

A card in a deck of playing cards can be represented by its rank or face value (2 - 10, jack, queen, king, ace) and its suit (clubs, diamonds, hearts, spades).  You should declare a structure type with fields of rank (or face value) and suit to represent a playing card, and then declare an array of these structures to represent a player's hand.

Evaluate each player's hand as follows:

 

1)  Assign a point value for each card:

      rank        points

     --------    --------

      2 - 10        0

      jack           1

      queen        2

      king           3

      ace            4

 

2)   Award one extra point for each suit that has only one card and that card is not a face

      card (face cards are jack, queen, king, ace).

3)   Award two extra points for each suit that is void (player has no cards of that suit).

Output should be the contents of each player's hand by suit, and the number of points represented by the hand.  You may wish to display the symbol for clubs, diamonds, etc.

(ASCII number 3 = heart, 4 = diamond, 5 = club, 6 = spade) instead of displaying the words "clubs", "diamonds", etc., or you could print the suit symbol after each card instead of or in addition to the words for the suit names.  Also you may prefer to print 10 instead of T.  The four hands may be output one after another rather than side by side as shown below.

 

   NORTH                                  EAST

   Clubs    A  T  8  7  6  2              Clubs    9  5  4

   Diamonds 8  7  6  3                    Diamonds K  T  4

   Hearts                                 Hearts   A  Q  9  8  7  2

   Spades   K  9  3                       Spades   5

   Points = 9                             Points = 10

 

   WEST                                   SOUTH

   Clubs    K  J                          Clubs    Q  3

   Diamonds J  9  5  2                    Diamonds A  Q

   Hearts   J  6  3                       Hearts   K  T  5  4

   Spades   Q  7  6  4                    Spades   A  J  T  8  2

   Points = 8                             Points = 16

 


Input file:  bridge.txt

Ordinarily you would randomly deal cards to each player to simulate a real game.  However,  having you read from a file allows me to distribute the cards in such a way as to make sure your program handles situations like an empty suit without my (and your) having to deal multiple games.

 

The file will be in this format with one line per player:

col    1     player      N (north), S (south), E (east), or W (west)

        3 -   cards       13 cards, in this format:  4H TD KS QH JS 2D 5C  (where T means 10)

                              (cards will be in random order as they might actually be dealt)

Requirements:

1)  You must represent a card as a structure (declare a type globally).

2)  You must represent the players' hands as one or more arrays.

3)  You must pass a structure to a function at least once.  For example, pass a card

     to a function which will return the number of points for the card, or pass a card to 

     a function which will display the card.

 

Extra Credit Opportunity:

For an extra 10%, list the cards in each suit in a player's hand from highest to lowest rank (face value) as shown in the sample output.