Programming Assignment II


Due: At midnight, May 7, 2008. Work turned in after that time will not be accepted for grading.

Program Description

For this project you will code a computer game that allows the user to play video poker. Here are the rules for the game:
  1. The player is given initiallly 20 dollars
  2. Each round of play costs the user 1 dollar.
  3. The player is dealt 5 cards from a standard 52 deck of playing cards.
  4. The player is then allowed to select some cards to keep and some cards to discard. They may discard any number of cards ( 0 to 5 inclusive).
  5. The player is then dealt additional cards until they again have 5 cards.
  6. The hand of 5 cards is evaluated to determine what type of poker hand it contains. Based on the type of hand, the player receives a payoff.
  7. Play continues until the user indicates they wish to quit or (s)he runs out of money.
The possible poker hands and their probabilities are described below:
 --------------------------------------------------------------------
a. No pairs [5 different face values, not in sequence, not all cards 
   in the same suit]                     
Prob(5 different face values, not in sequence, not in same suit) = 0.501177                                                
----------------------------------------------------------------------
b. One pair [two of one face value, and 3 cards of different face 
   values, no matching the pair]                
Prob(1 pair)  = 0.422569
 ----------------------------------------------------------------------
c. Two pairs [one pair of each two different face values and a card of 
   a third face value]
   Prob(2 pairs)   = .0475390
----------------------------------------------------------------------
d. Three of a Kind [exactly 3 cards of one face value and 2 different 
   cards]
Prob(Three of a kind)   = .02112845
----------------------------------------------------------------------
e. Straight [5 cards in sequence, but not all of same suit.  Ace high 
   or low]  
Prob(straight)   =  .0039246
----------------------------------------------------------------------
f. Flush [5 cards of the same suit but not in sequence, not including 
   the straight flush and royal flush below]
Prob(Flush)    = .0019654
----------------------------------------------------------------------
g. Full house [3 cards of one face value and 2 cards of another face 
   value]
Prob(Full house)   =  .00144058
----------------------------------------------------------------------
h. four of a kind [four cards of one face value and one other card]
Prob(Four of a kind) =    .00024009
----------------------------------------------------------------------
i. straight flush [five cards in sequence and of the same suit, but 
   not ace king queen jack ten]
 Prob(Straight flush) = .00001385
----------------------------------------------------------------------
j. Royal Flush [ace, king, queen, jack, ten in the same suit]
Prob(Royal flush) =  .000001539
---------------------------------------------------------------------
If you want to know how these probilities are computed, see:
http://mathforum.org/library/drmath/view/56616.html For another source, see Ivars Peterson's MathLand, September 7, 1996, in Science News Online: http://www.sciencenews.org/sn_arch/9_7_96/mathland.htm

You should start with the Card.java, Deck.java, Hand.java, PokerHand.java classes (see weeks 10-11 assignments). You should add new methods to PokerHand like isPair(), isTwoPairs(), isThreeOfKind(), etc. to test for possible poker hands. Add as many of these methods as you can. If you cannot add all of them, at least add isPair() and several others. You may need additional methods depending on your design.

You should decide on the payoffs in light the probabilities given above. For example, if machine pays 1-to-1 for a pair, machine would be ahead (probability for a pair is less then 0.5).

To start out, construct a deck and shuffle it. Deal a hand consisting of the first five cards of the deck. Replace as many cards as requested by the player; replacement cards should come in sequence from the 6th-10th cards of the deck. After one play, you can shuffle the deck again and start over.

You can decide how the replacement of the cards and the user interface in general should operate. To give you an idea, here is a possible run.


Let's play poker.
Your current hand is: 
        1 : 2 of Diamonds 
        2 : 9 of Diamonds 
        3 : 4 of Hearts 
        4 : 10 of Clubs 
        5 : 4 of Diamonds 
Enter the numbers of the cards you wish to discard.
Entering the number of a discarded card retrieves it.
Enter 0 to stop discarding.
1
        1 : 2 of Diamonds  DISCARDED
        2 : 9 of Diamonds 
        3 : 4 of Hearts 
        4 : 10 of Clubs 
        5 : 4 of Diamonds 
Select another card or 0 to complete the discard.
2
        1 : 2 of Diamonds  DISCARDED
        2 : 9 of Diamonds  DISCARDED
        3 : 4 of Hearts 
        4 : 10 of Clubs 
        5 : 4 of Diamonds 
Select another card or 0 to complete the discard.
4
        1 : 2 of Diamonds  DISCARDED
        2 : 9 of Diamonds  DISCARDED
        3 : 4 of Hearts 
        4 : 10 of Clubs  DISCARDED
        5 : 4 of Diamonds 
Select another card or 0 to complete the discard.
0

Your final hand is: 
        1 : 6 of Spades 
        2 : King of Hearts 
        3 : 4 of Hearts 
        4 : 10 of Diamonds 
        5 : 4 of Diamonds 
You have a pair.
You now have $21.
Do you want to play again [y/n]?
y
.....
etc...
Good Luck.