The card game of Duplicate Contract Bridge is a fascinating game which engages the mind like no other card game. It is probably the most played card game worldwide and there are many competitions held internationally with attractive prizes.
A deck of cards has 52 cards (excluding the jokers). Each card has a suit and a rank. The suit can be any one of Spades, Hearts, Diamonds, or Clubs. The rank can be any one of Ace (the highest), King, Queen, Jack, Ten, Nine, Eight, Seven, Six, Five, Four, Three, or Two (the lowest). There are a total of four different suits and 13 different ranks.
Each suit and rank is respresented by a short form according to the following two tables:
Suit | Short Form |
---|---|
Rank | Short Form |
---|---|
In a bridge deal, the 52 cards are shuffled and dealt completely into four hands, with each hand receiving 13 cards. The hands are labelled according to the directions on a compass: North, East, South, and West. Bridge deals are stored in a file in Portable Bridge Notation (PBN). It is your job as the computer programmer to write a program that reads in a file in PBN format and displays the bridge deal on the screen in a nice human readable format.
Each bridge deal is defined as "<north_hand> <east_hand> <south_hand> <west_hand>". A space character exists between two consecutive hands. The cards of each hand are given in the order: Spades, Hearts, Diamonds, Clubs. A dot character "." exists between two consecutive suits of a hand. The cards of a suit are given by their ranks. The ranks are defined as (in descending order): A , K , Q , J , T , 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2. Note that the 'ten' is defined as the single character "T". If a hand contains a void in a certain suit (meaning there are no cards of a particular suit), then no ranks are entered at the place of that suit.
An example bridge deal is given below:
5.76.AK97654.Q32 AK84.AKT3.Q.J965 T632.854.J.AK874 QJ97.QJ92.T832.T
Examine the north hand, and you will see that it is:
5.76.AK97654.Q32
The suits are arranged in the order Spades, Hearts, Diamonds, Clubs. So there is only one Spade card (the 5), two Heart cards (the 7 and 6), seven Diamond cards (the Ace, King, 9, 7, 6, 5, 4), and three Club cards (the Queen, 3, 2). The above must be displayed in the following format:
Player North: S5 H7 H6 DA DK D9 D7 D6 D5 D4 CQ C3 C2
Notice that each card is shown by two characters: its suit (S, H, D, C) followed by its rank. So S5 means the Spade 5, or the 5 of Spades, and DA means the Diamond Ace, or the Ace of Diamonds.
For the above bridge deal, the entire output should be as shown (follow the format exactly!):
Deal #1: Player North: S5 H7 H6 DA DK D9 D7 D6 D5 D4 CQ C3 C2 Player East : SA SK S8 S4 HA HK HT H3 DQ CJ C9 C6 C5 Player South: ST S6 S3 S2 H8 H5 H4 DJ CA CK C8 C7 C4 Player West : SQ SJ S9 S7 HQ HJ H9 H2 DT D8 D3 D2 CT
Bridge deals in PBN format are stored in pbnin.txt. Multiple bridge deals are stored in separate lines. Your program must process pbnin.txt and store the output into pbnout.txt. For example, if pbnin.txt contains:
5.76.AK97654.Q32 AK84.AKT3.Q.J965 T632.854.J.AK874 QJ97.QJ92.T832.T J76.J98542.74.AK 52..AKQ8652.QJ83 AKQT8.KT6.J3.965 943.AQ73.T9.T742
then pbnout.txt must contain (note the numbering of the deals and follow the format exactly):
Deal #1: Player North: S5 H7 H6 DA DK D9 D7 D6 D5 D4 CQ C3 C2 Player East : SA SK S8 S4 HA HK HT H3 DQ CJ C9 C6 C5 Player South: ST S6 S3 S2 H8 H5 H4 DJ CA CK C8 C7 C4 Player West : SQ SJ S9 S7 HQ HJ H9 H2 DT D8 D3 D2 CT Deal #2: Player North: SJ S7 S6 HJ H9 H8 H5 H4 H2 D7 D4 CA CK Player East : S5 S2 DA DK DQ D8 D6 D5 D2 CQ CJ C8 C3 Player South: SA SK SQ ST S8 HK HT H6 DJ D3 C9 C6 C5 Player West : S9 S4 S3 HA HQ H7 H3 DT D9 CT C7 C4 C2
Do not change the ordering of the cards.
Warning: In Deal #2, note that the east hand does not have any heart cards. Your program must be able to handle such cases.
A sample pbnin.txt file has been placed in your directory by the pesetup program.
Assume that pbnin.txt exists and there are no errors in the file.
We will test your program with other pbnin.txt files.
All the best!
Some useful UNIX commands (in case you forgot what you did in Lab 0):