Project #5 CMSC 131
Due:  Friday November 13, 11:00PM Object-Oriented Programming I
Type of Project: Closed Fall 2009

Texas Hold 'Em Simulator

Closed Policy

This is a closed project.  You are expected to do all of the work on this project without consulting with anyone other than the CMSC 131 instructors and TAs.  Treat this project as though it were a take home exam.  If you have any questions about whether or not a certain topic is okay to discuss with classmates or friends, please ask your instructor.

 

Overview

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..

 

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.

 

Card Class (Provided)

Before you get started, you should read the JavaDoc for the Card class.  You will use this class while writing your classes.

 

Classes You Must Implement

There are two classes you must implement.  (You will also write a series of JUnit tests, described below.)  We have given you just "skeletons" for the classes to get you started.  The two classes you will write are:

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:

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 above, the Ace of Spades is at the TOP of the deck, which is to the left.

 

 

 

 

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

 

Before cut

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

 

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".

20% 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.

 

Requirements

 

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.)

 

Grading

Your grade will be computed as follows: