CS 340 - Machine Problem 2

Card Game: Poker - 5 Card Draw

Due: 11:59 pm on Monday 10/2/2006

For this assignment you must work alone.

For this assignment, you are to implement the card game of Five Card Draw in Poker. The Five Card Draw explains the order in which cards are given to the players and Poker determines the "value" of each hand.

The game is played using a standard deck of 52 cards. Each card has a Rank and Suit value. There are 13 Ranks and 4 Suits making the 52 cards in the deck. The Suits are colored either Black or Red. The cards are to be listed using a two character sequence for each card. The first character is to specify the rank of the card and the second character is to specify the suit. The ranks and suits with the associated characters are given in the table below. Use upper case letters when specifying cards.

Rank Characters Suit Characters
  • 2 - Two
  • 3 - Three
  • 4 - Four
  • 5 - Five
  • 6 - Six
  • 7 - Seven
  • 8 - Eight
  • 9 - Nine
  • T - Ten
  • J - Jack
  • Q - Queen
  • K - King
  • A - Ace
  • C - Clubs (Black)
  • D - Diamonds (Red)
  • H - Hearts (Red)
  • S - Spades (Black)
Note that the ranks and suits are listed in order with Two being the low rank, Ace being the high rank, Clubs being the low suit and Spades being the high suit. In the game of Poker, an Ace can being either low or high. It should be treated as a high rank except in the case of a "straight" (to be explained below). The rank of a card has higher priority than the suit of the card. The suit is used when comparing two card only if the ranks are the same. Thus:
     7C > 5S   and    8H > 8D
According to the wikipedia, the suits don't impact the game of poker except when determining a flush. We will use the rules described at its Rank of Hands page as our official rules.

The Game's Idea

In the game of five card draw the following actions occur.
  1. The 52 cards in the deck are shuffled (randomized) and put in the "draw pile".
  2. Then each player is given one card in some determined order. This is repeated (using the same order of players) until each player has 5 cards. This is card "dealing" the cards"
  3. The first player is allowed to discard up to 3 cards from their hand (the "first" player is player at the beginning of the order from step 2) The player can discard a 4th card only if the remaining card in the player's hand is an Ace. The cards that are discarded are put into a "discard pile" which is separate from the "draw pile". The player then given enough cards from the "draw pile" so that the player will have 5 cards. Following the same order that was used in dealing the cards, this is repeated for the other players.
  4. Now the hands are evaluated and the winner is determined.

The Evaluation of Hands

Refer to wikipedia's page on poker's rank of hands for our official page on this. It has a great way to determine how a determine ties and how to dtermine winners when things appear the same. The evaluation of hands from highest to lowest is:

The Prompt for the User Player

Your program must give some messages and prompt as the game is played.
  1. The first prompt given to the user is the number of computer opponents. Your program must allow answers from 1 to 3. You can allow less computer oppenents (i.e. zero) or more as you wish, but your program must accept the values 1, 2 and 3.

  2. The program should then give some messages about the play of the game (i.e. "the desk is being shuffled", "the cards are being delt to 3 players").

  3. The game is next in the "discard and draw" phase. When its is a computer opponent's turn to discard and draw, your program must display a message something like:
         Computer Player 1 has discarded 3 cards.
    When it is the user player's turn, you must show the five cards in the players hand and allow the user the select which cards will be discarded. Perhaps there is a prompt such as:
         The cards in your hand are: 1) AS  2) KH  3) TD  4) TC  5) 6S
         Since you have an Ace you can keep the Ace and discard the other 
    	four cards. 
         List the cards numbers you wish to discard. >
  4. Now show all of the hands, specify what type of hand it is (i.e. One Pair, Three of a Kind, etc) and list the winner.

  5. Then thank the player for using the program and list whatever information you wish about the program. Finally end the program.
When showing the cards in a hand, sort the cards from highest to lowest with the highest card being listed first (on the left).

For 5 points extra credit, sort the cards so that any matched cards are list first. When multiple matched cards are in the hand (i.e. two pair or full house), list the more important match first. This would be the match with the higher rank for two pair and the match of three for the full house. Doing this will make breaking ties extremely easy. So you are strongly encouraged to do this. Not only will you get extra credit, but this will simplify a potentially difficult part of the assignment.

The Computer Player's AI Algorithm

For the computer player's turn, use the following AI algorithm.
  1. First check if the computer player already has a hand of One Pair or better. If so, discard all other card.
  2. If the hand evaluates to "High Card", determine if the user has 4 cards of the same suit. If so, discard the card of the different suit.
  3. Next determine if the user has 4 cards in sequence. of the same suit. If so, discard the card that is out of sequence.
  4. Next if the user has an Ace, discard the other four cards.
  5. Otherwise, keep the two highest cards and discard the other 3.

Class Requirements

You must write at least 5 classes for this program. These classes are:
  1. A Card Class - This class will keep the information about each card.
  2. A Card Pile Class - This class is a collection of cards. While this class cannot just be an STL class. You may use an STL class instance as a data member of the Card Pile Class.
  3. A User Player Class - This class will keep track of the user's hand and interact with the user interface.
  4. An Opponent Player Class - This class will keep track of the computer player's hand and interact with the Artificial Intelligence.
  5. A Game Class - This class will keep track of the particulars of the game, such as the order of actions of the game (shuffling, dealing, discarding and determining the winner) and the evaluation of the hand (does the player have a Straight Flush, Four of a Kind, Full House, etc.). Actually it might be better to divide this into two classes: one to deal with the order of the actions and one to evaluated the hands.

General Comments

Your program must be written in good programming style. This includes (but is not limited to) meaningful identifier names, a file header at the beginning of each source code file, a function header at the beginning of the function, proper use of blank lines and indentation to aide in the reading of your code, explanatory "value-added" in-line comments, etc.

The work you turn in must be 100% done by your own own. You are not allowed to share code with any other students (inside this class or not). You may discuss the project with other students; however, you may not show any code you write to another student nor may you look at any other student's written code.

You are to submit this using turnin on the CS Department machines with the project name of mp2. The turnin command would be

 turnin -c cs340 -p mp2 <filename(s)>
Where <filename(s)> would be the name of the file(s) you want to submit for grading. You can verify what you submitted by using the command:
 turnin -c cs340 -p mp2 -v