Overview

This project is considered "CLOSED". Please visit the course web page for information regarding the open/closed policy for projects of this course.

This project will simulate something close to a game of Texas Hold 'Em, which is a style of poker.  If you don't know how to play this game (or if you've never played cards before in your life), don't worry -- we'll explain everything!  Most of this program will be written for you.  We will provide the graphical interface and most of the infrastructure for the project.  You will supply two classes (and a series of JUnit tests).  The classes you will write are:  Deck, which represents a deck of cards, and  PokerHandEvaluator, which contains several static methods that evaluate a set of 5 cards to determine which "poker" hands are represented..

Objectives

To practice one-dimensional arrays.

Grading

Clarifications

Any clarifications or corrections associated with this project will be available at Clarifications

Code Distribution

The project's code distribution is available by checking out the project named Poker. The code distribution provides you with the following:

Specifications

Cards

If you are not familiar with the standard deck of 52 playing cards and the terminology that goes along with it ("suit", "queen", "clubs", etc.), then please take a look at the Playing Card Page.

Poker Hands

If you are not familiar with poker hands, such as "Full House" or "Straight Flush", then please read the Poker Hand Page.  By the way, to successfully implement this project you need to know the definitions of these hands very precisely, so unless you are a real expert it would be a good idea to read this information carefully!

(Partial) Rules of Texas Hold 'Em

If you are not familiar with this game, then please read the Introduction to Texas Hold 'Em Page.

Classes You Must Implement

  1. Deck.java
    The Deck class represents a deck of cards.  It starts off with 52 cards, but as cards are dealt from the deck, the number of cards becomes smaller.  The class has one private instance variable that stores the Cards that are currently in the Deck:

    private Card[] cards;

    Important Note: The first Card in the array will be considered the card that is at the top of the deck.  When cards are removed from the deck they will be removed from the front of the array. You must implement the following methods for the Deck class:

    • public Deck() - This constructor initializes the Deck with 52 card objects, representing the 52 cards that are in a standard deck.  The cards must be ordered as in the diagram below: Important:  The FIRST card in your array should be the Ace of Spades, and the LAST card should be the King of Diamonds.  Note that in the picture below, the Ace of Spades is at the TOP of the deck, which is to the left.

    • public Deck(Deck other) - Standard copy constructor.  Note that it is okay to make a shallow copy of the array of cards.  (The Card class is immutable, so aliasing Cards is not a problem.)
    • public Card getCardAt(int position) -- Returns the card that is at the specified position in the array.  (Uses the usual 0-based indexing.)
    • public int getNumCards() - Returns the size of the array of Cards.  (It starts off equal to 52, but becomes smaller as cards are dealt from the deck.)
    • public void shuffle() - This method will re-arrange the cards that are in the deck.  The idea is that the deck will be divided into two "packets" -- the top half and the bottom half.  The new array of cards will consist of:  the first card from the top packet, followed by the first card from the bottom packet, followed by the second card from the top packet, followed by the second card from the bottom packet, etc.  Important:  If there are an odd number of cards, the top packet should have one more card than the bottom packet.  Remember that the top of the deck is considered to be the front of the array.  In the pictures below, remember that the top of the deck appears at the left side. Below are two examples of how the shuffle should work.

    Example 1 (even number of cards):

    Before Shuffling

    After Shuffling

     

    Example 2 (odd number of cards):

    Before Shuffling

    After Shuffling

     

    • public void cut(int position) - This method divides the deck into two subpackets:  The part above the specified position, and the part that is at the specified position or below.  The two subpackets are reversed (the top packet is placed on the bottom and the bottom packet is placed on the top.)  The position value uses 0-based indexing as usual, so the card at the top of the deck (to the left in the diagrams) is at position 0.  Here is an example:

    Before cut

    After cutting at position 4.  (The 5 of spades was at position 4 in the diagram above.)

     

    • public Card[] deal(int numCards) - This method will remove the specified number of cards from the top of the deck and return them as an array.  For example, if the parameter is 4, then the first four cards in the deck will be returned as an array of size 4.  Important:  The cards will be removed from the front of the "cards" array, not the back. Hint:  The "cards" array will need to be resized.  Here is the idea:

      • Make a new array (call it "smaller") that is the same size as the current deck of cards minus the number of cards being dealt.
      • Copy the cards that are not being dealt from the original array into the new one.
      • Assign the instance variable "cards" so that it refers to the new array.


  2. PokerHandEvaluator.java
    This class consists of several static methods that you will write.  The prototypes for the methods are:

The parameter for each of these methods will be an array of exactly 5 cards.  Each method will return true or false, based on whether or not the given set of cards satisfies the poker hand being evaluated in the method.   For example, the hasTwoPair method will return true if the set of cards has two pairs of different values (e.g. a pair of 4's and a pair of Jacks).  If you need to review the various "poker hands" being tested in the methods, please take another look at the Poker Hand Page.

Important:  Each of these methods checks whether or not the set of cards satisfies the given poker hand, but it does not care if it could also satisfy a better hand.  For example, if the current hand is

<Ace of diamonds, Ace of spades, Ace of hearts, Jack of Spades, Jack of Diamonds>

then the results of calling each method should be as indicated below:

Important:  In order for a hand to qualify as "Two Pair", it must have two pairs of distinct values -- in particular, having four-of-a-kind does not also count as two pair.  For example, if the current hand is

<2 of diamonds, 2 of spades, 2 of hearts, 2 of clubs, 9 of spades>

then the results of calling each method should be as indicated below:

 

JUnit Tests

You are required to submit JUnit tests for all of the methods in the PokerHandEvaluator class.  Your tests should be as thorough as possible!  Be sure that for each method you have written some tests where the method returns "true", and some tests where the method returns "false".

10% of your grade on this project will be determined by the thoroughness of the tests you write.  (Note:  To get any credit at all for your JUnit tests, your project must pass all of the tests you have written!)  Put your tests into the file provided called "StudentTests.java".   If the tests are not located in this file, you will not get credit for them.

Running the Simulation

To run the simulation, execute the main method in the Driver.java class.  Before clicking on the "Deal" button, you will usually want to do a series of "cuts" and "shuffles".  (You can cut the deck by clicking somewhere in the middle of the deck.  Shuffle is accomplished by clicking a button.)

Requirements

Additional Requirements for Students in Honors Section

No additional requirements.

Web Accessibility