The features with this background are optional.

The application is a simulation of the auction bidding for the game of Contract Bridge. The following parameters will apply:

  • There is no input.
  • You will have a function/method called withPermutation (see particular assignment for exact name) that takes one parameter which is a collection of the order of the deck (i.e. a shuffling). It will be a sequence of numbers in the inclusive range 1..52. The cards in an unshuffled deck will be in the order of clubs (♣ C), diamonds (♦ D), hearts (♥ H), spades (♠ S), with each suit ordered as 2..10,J,Q,K,A. The permutation will tell you which card goes in each position of the shuffled deck. For example, a list that started with [38, 48, 11, 6,...] would mean a deck shuffled to start with [KH, 10S, QC, 7C,...] This function is the main entry point to the program and will print out the dealt hands and do the bidding as described below.
  • You may have a function/method called play that will generate a random shuffling of the integers 1..52 (ideally using the Fisher-Yates shuffling algorithm) and pass that to the function/method above.
  • The players in a traditional bridge hand are called South, West, North, and East (shown in those compass positions). The players play as 2 teams: North-South versus East-West. For our purposes, South will deal the cards out. Cards are dealt sequentially, starting with the person on the dealer's left, going around the hands, so that South gets the cards in position 4,8,12,...52. You will print out the dealt cards in the standard layout. Below the dealt hands, show the bidding, and who is declarer. The full output is shown here for the permutation [ 38, 48, 11, 6, 20, 17, 46, 8, 37, 43, 7, 52, 36, 10, 25, 49, 50, 16, 33, 5, 42, 32, 9, 29, 1, 51, 26, 18, 41, 15, 40, 31, 35, 45, 4, 12, 39, 30, 19, 21, 2, 34, 23, 3, 27, 22, 47, 14, 24, 28, 13, 44]:
    North
    S K 10 7 5
    H 9 7 5 3
    D 10 5 4 3
    C J
    West
    S Q 4 3
    H A K Q J 10 2
    D Q 8
    C 3 2
    East
    S 9 8 2
    H 8
    D A K J 7
    C A Q 10 8 5
    South
    S A J 6
    H 6 4
    D 9 6 2
    C K 9 7 6 4
       SouthWestNorthEast
    Pass1HPass3C
    Pass4HPassPass
    Pass
    Declarer: West

    Note that the cards are printed out from highest to lowest in each suit with one space between each card.
    Also note that the North and South hands are indented to the character after the longest suit in the West hand, and the East hand is indented to the character after the longest suit in the North or South hands. In other words, the hands should not overlap at all. There also should be no spaces after the end of the suits in the North, South, or East hands.
  • The auction starts with the dealer, and proceeds in clockwise order until 3 consecutive passes have been registered. The last bid before the 3 consecutive passes establishes the trump suit and the number of tricks that the declarer team is committing to winning. Whole books have been written about bidding for the game of Bridge, and there are various ways to count points, but you will use the following rules (even if you're an expert bridge player and know many better ways, you must ignore those and follow these). While this is long and may seem complicated, it actually boils down to a fairly small amount of code.
    • For each hand, count the points:
      • Aces - 4 points each
      • Kings - 3 points each
      • Queens - 2 points each
      • Jacks - 1 points each
      • Voids (an empty suit) - 3 points each
      • Singletons (a suit with only 1 card) - 2 points each
      • Doubletons (a suit with only 2 cards) - 1 points each
      (Yes, we know that, for example, a singleton Jack isn't usually counted as 3 points, but we are keeping this simple!)
    • Although this assignment is just about bidding (whole other books have been written about how best to play bridge!), here is a short description of play to give you context for the bidding. Bidding is a competitive auction to get to decide which team can earn points in the round. Each bid is for a suit, and a number of "tricks" that you commit to winning - the number of tricks bid is in addition to "book" which is 6 tricks. The suit of the winning bid becomes the "trump" suit for the hand. So if the winning bid is 4 hearts by West, then it means that East-West are committing to winning at least 10 tricks (of the 13 possible) and that hearts will be trump - whichever of East or West first bid hearts is declarer (West in the example deal). A trick is when the person who won the previous trick (or the person clockwise to declarer for the first round) leads a card and the other 3 players in clockwise order plays a card following the suit of the card led, unless they are void in that suit, in whiccase they may play a trump if they have one or discard some other suit. Whichever person played the highest card in the suit that was led, or the highest trump, wins that trick and has the lead. When all the cards have been played, if the declarer team has taken at least the contracted number of tricks, they get points; otherwise the other teeam gets points (since we're not talking about play, we'll ignore the scoring, too).
    • In addition to the 4 suits, you can bid "No Trump" (NT). If the winning bid is NT, then the play proceeds normally except the highest card of the suit led is always the winner, since there is no trump suit.
    • Every bid except the first must be higher than the previous bid - either a higher suit at the same numeric level (Clubs < Diamonds < Hearts < Spades < No Trump) or at a higher numeric level (to a maximum of 7). You can think of the bids as a linear progression of 1C, 1D, 1H, 1S, 1NT, 2C, 2D, ..., 7S, 7NT. Thus if the previous bid is 1 heart and you want to bid spades or not trump, you can bid at the 1-level. If you want to bid clubs, diamonds, or hearts, you will have to bid at least at the 2-level.
    • Because of scoring details that we won't go into, a team will usually try to bid a "game" which is 3NT, 4S, 4H, 5D, or 5C. There is no point bidding higher unless the team thinks it can will all tricks (7 - a "Grand Slam") or all but one (6 - a "Small Slam") which earn bonus points. Clever play (by either declarer or the defenders) can change the outcome, but generally success is a function of how many points the declarer team has:
      • 25 points - 3NT (high card points only)
      • 27 points - 4H or 4S
      • 29 points - 5C or 5D
      • 32 points - small slam
      • 36 points - grand slam
      So a lot of the bidding is trying to find a suit fit and determining how many points the team has - and thus where to stop bidding.
    • When bidding, you can only look at the bidding so far. You can not look at the cards in another hand to help your bidding.
    • Bidding continues until there are 3 consecutive passes. But if nobody opens, you will see 4 passes, because everyone needs an opportunity to bid at least once.
    • A "no trump hand" means you have no singletons or voids and no more than 1 doubleton, and stoppers in all suits (so the suit has an ace or king, or a queen with 2 other cards, or a jack with 3 other cards)
    • Opening
      • If you are the first hand to bid for a team, you must have opening points to bid. Opening points are 13 or more. You want to bid your strongest suit, and you want to communicate to your partner how many points you have.
      • If your longest suit is 5 cards or more, bid that at the lowest possible level (typically a 1 bid).
      • if you have at least 16 points and a no-trump hand, you would open with no trump at the lowest possible level (typically a 1NT).
      • Otherwise, bid the longer (meaning more card in the suit) and stronger (meaning if the same length, the one with more points) of clubs or diamonds, choosing clubs if they are the same length and points.

      In the deal shown above, South passes (because they only have 9 points), and West opens the 6-card suit (because while they have 16 points, they don't have a no-trump hand (2 doubletons, and no stoppers in clubs or diamonds)).

    • If your partner hasn't opened and you have less than 13 points, pass.
    • Answering
      • If you have 13 or more points bid at a level 1 higher than required, to show the points. If you have 3 or more cards in your partner's suit, raise that; otherwise if you have a no-trump hand, bid that; otherwise, bid your best suit.
      • If you have 10 or more points, if you have a no-trump hand, bid no trump; otherwise your best suit and you can go to the next level.
      • If you have 8 or more points bid your best suit, if you can do it at the same level.
      • If you have 6 or more points and at least 3 cards in partner's suit, raise them by 1 in that suit.
      • Otherwise, pass.

      In the deal shown above, North passes (because they only have 6 points they can't open, and because partner didn't open, they can't answer), and East answers their best suit (because they have 16 points, they don't have 3 cards in partner's suit and don't have a no-trump hand (a singleton, and no stoppers in hearts or spades)) at one level higher than required (because clubs is before hearts, the lowest club bid they could possibly make would be 2C, so they bid 3C to show their 13+ points).

    • If you opened, use your partner's bid to decide what your final bid should be. For our purposes, only bid a second time if your points plus the minimum range from your partner's total up to one of the point requirements above in item number 5.5. If so, bid at that level. If you have at least 4 cards in your partner's bid suit, bid that, otherwise bid your original suit. I.e.,
      • if you or partner bid no-trump, and the team has at least 25 points, bid 3NT
      • if either you or partner bid hearts or spades (and if it was partner, you have at least 4 cards in that suit), and the team has at least 27 points, bid 4 of that suit (if both qualify, bid your original suit)
      • if either you or partner bid clubs or diamonds (and if it was partner, you have at least 4 cards in that suit), and the team has at least 29 points, bid 5 of that suit (if both qualify, bid your original suit)
      • if one of the preceeding 3 rules applies, but your team has at least 32 points, bid 6 of that suit
      • if one of the preceeding rules applies, but your team has at least 36 points, bid 7 of that suit
      • else, pass

      In the deal shown above, South passes again (because they only have 9 points they still can't open, and because partner didn't open, they can't answer), and West bids their original suit (because between them the team has 29+ points (West's 16 plus East's bid indicated 13+ points), West doesn't have 4 cards in partner's suit and so bids their original suit)

    • For our purposes, the answerer will not bid a second time.
    • The last bid before the 3 passes determines what is trump (or no trump) and the number of tricks that team is contracting to make.
    • Declarer is the first person who bid the trump suit on the team who won the bidding, even if their partner made the last bid before the 3 passes, and even if the opponents bid that suit at some point.
    • This is a huge simplification. In real bidding you would take into account what the opponents were bidding. Both teams may be bidding, but for our purposes, they are independent.
  • In addition to any tests or test data we provide, you must have unit tests for the components of your program, verifying that they perform correctly. This will be worth 20% of the mark.