Draw Poker
Concepts Covered: Building a program from scratch that uses multiple classes; incremental programming
Due: Preferably at the end of the day on Wednesday
Files you need: Card.java, Deck.java, PokerHand.java
Turn in: DrawPoker.java
Background: Poker is a card game in which players bet on the value of their five-card hand (which is unknown to the other players). There are several different variations. One thing that they all have in common is the ranking and interpretations of the five-card hands. Here is a list from highest rank to lowest rank:
In this project you will write a simple draw poker program.
Requirements: You have been given classes that represent Card, Deck and PokerHand objects. Your job is to use these pre-written classes to write a draw poker game. The rules of draw poker are simple - the computer deals a 5 card poker hand to the player. The player may then discard up to 3 (or 4 if they have an ace) cards and are dealt new cards. The rank of the hand is then evaluated, and the player is awarded his bet times a multiplier based on the rank of the resulting hand.
Your program should start by giving the player 1000 points and letting her bet. It would first subtract the bet from her money. Then it would deal her a hand and let her select the cards to discard (up to 4 if she has an ace, up to 3 otherwise). It would call the "draw" method on those cards, reevaluate the rank and then reward her with a multiplier based on the rank of her hand as follows:
Here is an example of how a deal and a draw might look in your program (assuming you have a Deck d and a PokerHand h):
h = new PokerHand(d.deal(), d.deal(), d.deal(), d.deal(), d.deal());
h.draw(0, d.deal()); //discards the first card and replaces it
h.draw(4, d.deal()); //discards the fifth card and replaces it
After your run your program, the output might look something like this:
purewal@atlas % java DrawPoker
Welcome to Draw Poker!
You currently have 1000 points.
Enter bet for this hand: 250
I have just dealt you the following hand:
(1) 2 of Hearts
(2) 5 of Clubs
(3) 5 of Diamonds
(4) K of Hearts
(5) A of Spades
You have an ace so you may draw up to 4 cards!
Which card would you like to discard (1 - 5, or 0 to stop drawing): 1
Which card would you like to discard (1 - 5, or 0 to stop drawing): 4
Which card would you like to discard (1 - 5, or 0 to stop drawing): 5
Which card would you like to discard (1 - 5, or 0 to stop drawing): 0
Your hand is now:
(1) 3 of Diamonds
(2) 5 of Clubs
(3) 5 of Diamonds
(4) 5 of Spades
(5) Q of Clubs
This hand is a Three of a Kind!
You win 2x your bet of 250 which is 500!
You now have 1250 points!
Would you like to play another hand (y/n): y
You currently have 1250 points.
Enter bet for this hand: 100
I have just dealt you the following hand:
(1) 4 of Clubs
(2) 5 of Diamonds
(3) 7 of Hearts
(4) J of Diamonds
(5) K of Spades
You may draw up to 3 cards!
Which card would you like to discard (1 - 5, or 0 to stop drawing): 1
Which card would you like to discard (1 - 5, or 0 to stop drawing): 2
Which card would you like to discard (1 - 5, or 0 to stop drawing): 3
Your hand is now:
(1) 2 of Diamonds
(2) 3 of Clubs
(3) J of Diamonds
(4) J of Spades
(5) K of Clubs
This hand is a Pair!
You lose your bet of 100!
You now have 1150 points!
Would you like to play another hand (y/n): n
Thanks for playing!
purewal@atlas %
Make sure that the player does not try to bet more money than she has or a negative number! Also, don't allow the player to discard the same card twice (this is a tricky problem - make sure you think carefully about the solution).
The secret to writing this program is to do it incrementally - get the main shell working and then fill in the details as you go along. You should start with your "play again" loop and get that working. Next add the part for dealing the hand and make sure that works. Next add the part for drawing and make sure that works. Finally, add the betting mechanism. If you work in this manner, the program should be relatively easy to write.
In summary, do the following in order:
purewal@atlas % java DrawPoker
Welcome to Draw Poker!
Would you like to play another hand (y/n): y
Would you like to play another hand (y/n): y
Would you like to play another hand (y/n): y
Would you like to play another hand (y/n): y
Would you like to play another hand (y/n): y
Would you like to play another hand (y/n): n
Thanks for playing!
purewal@atlas %
purewal@atlas % java DrawPoker
Welcome to Draw Poker!
I have just dealt you the following hand:
(1) 2 of Hearts
(2) 5 of Clubs
(3) 5 of Diamonds
(4) K of Hearts
(5) A of Spades
Would you like to play another hand (y/n): y
I have just dealt you the following hand:
(1) 4 of Clubs
(2) 5 of Diamonds
(3) 7 of Hearts
(4) J of Diamonds
(5) K of Spades
Would you like to play another hand (y/n): n
Thanks for playing!
purewal@atlas %
purewal@atlas % java DrawPoker
Welcome to Draw Poker!
You currently have 1000 points.
Enter bet for this hand: 250
I have just dealt you the following hand:
(1) 2 of Hearts
(2) 5 of Clubs
(3) 5 of Diamonds
(4) K of Hearts
(5) A of Spades
You may draw up to 3 cards!
Which card would you like to discard (1 - 5, or 0 to stop drawing): 1
Which card would you like to discard (1 - 5, or 0 to stop drawing): 4
Which card would you like to discard (1 - 5, or 0 to stop drawing): 5
Your hand is now:
(1) 3 of Diamonds
(2) 5 of Clubs
(3) 5 of Diamonds
(4) 5 of Spades
(5) Q of Clubs
This hand is a Three of a Kind!
Would you like to play another hand (y/n): y
I have just dealt you the following hand:
(1) 4 of Clubs
(2) 5 of Diamonds
(3) 7 of Hearts
(4) J of Diamonds
(5) K of Spades
You may draw up to 3 cards!
Which card would you like to discard (1 - 5, or 0 to stop drawing): 1
Which card would you like to discard (1 - 5, or 0 to stop drawing): 2
Which card would you like to discard (1 - 5, or 0 to stop drawing): 3
Your hand is now:
(1) 2 of Diamonds
(2) 3 of Clubs
(3) J of Diamonds
(4) J of Spades
(5) K of Clubs
This hand is a Pair!
Would you like to play another hand (y/n): n
Thanks for playing!
purewal@atlas %