CMSC 131 - Fall 2019 - Project #6


Please note that there are two elements to this project; the deck of cards and the evaluation of hands of cards. They are related to each other in theme and in terms of practice with data structures and with logic and would both be needed to implement a full Starfish Card Games Simulator. However, the two elements do not interact in the JUnit tests, so if you get stuck on something in one element of the project, you can switch to working on the other until you have a chance to come in to office hours.

There is a Launcher.java class that will bring up a visualization of the deck with which you can interact to visually test building the deck, as well as cutting the deck, dealing from the deck, and shuffling the deck. The hand evaluators all need to be tested via JUnit tests for your own testing and debugging needs.

Suggested order of working on this project:
  • building the deck
  • being able to get individual cards from it and the number of cards in the deck
  • evaluating Patrickjack hands
  • being able to deal cards and get the number of cards in the deck
  • cutting the deck (and exception throwing on illegal requests)
  • evaluting hasPair, hasThreeOfAKind, hasFourOfAKind, hasFiveOfAKind
  • evaluting hasRainbow, hasStraight
  • the remaining non-challenge deck and hand elements


Suggested: You should aim to have the entire project done by November 17th.

Note: At this point in the semester, and especially after the Lab07 work, you should be ready to work on the majority of this without needing to see the TAs about this project. If you did not understand elements of Lab07, we strongly suggest you go to ask about those elements, and then work to apply your understanding on them to this assignment.

Graded: assignment submission due on Submit Server before 8pm on November 20th November 21st.

Type of project: Closed

Starfish Card Games Simulator

simulator start screen

Overview

In this project, you will utilize both Java's ArrayList class and Java arrays. The goal is to understand both and be able to consider the advantages and disadvantages of each so that in future courses, you can make educated decisions. It is critical that you use the storage approach we mandate in this project. For example, if we tell you to use an ArrayList for something (such as the Deck) and you use an array instead, all points associated with that will be deducted, even if it "passes" on the submit server.

This project will have you designing and implementing several related classes; a deck of cards and some game evaluation methods. The deck and games bear some similarities to a standard deck of cards and the games of Poker and Blackjack but there are differences; these are for the Starfish Casino, soon to open in Ocean City. You don't (and unless you hail from the vicinity of where SpongeBob lives, can't) have previous experience with this deck and these games. We'll explain everything! As always, you will have starter files provide and this document will specify the specifications for the methods. There is a GUI provided to allow you to "see" the deck to provide some help in debugging errors related to the deck, but JUnit testing will be your friend for much of this project!

You will design and implement one Java data structure class (the Deck which represents a deck of cards) using an ArrayList<Card> to store and manipulate the contents of the deck as well as HandEvaluatorSFCP, which contains several static methods that evaluate the contents of arrays of 5 cards to determine which "Starfish Poker" hand(s) are represented and HandEvaluatorPatrickjack, which contains two static methods that evaluate the contents of ArrayList objects connected to the game of Patrickjack. as well as a series of JUnit tests in another class.

Cards

If you are not familiar with the Starfish deck of 45 playing cards (which you aren't) and the terminology that goes along with it ("suit", "Ace", "clubs", etc.), then you'll need to take a look at the Playing Card 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.


StarDeckException Class (Provided)

We provide a class called StarDeckException to create a new RuntimeException for use by the Deck.


Deck.java

The Deck class represents a deck of cards.  It starts off with 45 cards, but as cards are dealt from the deck, the number of cards (and the ArrayList<Card> that holds them) becomes smaller.

The class has one private instance variable that stores the ArrayList<Card> of references to Cards that are currently in the Deck: You must use the ArrayList for this class. You may not add any arrays to this class except one place; the array that deal returns.

private ArrayList<Card> cards;

Important Note:  The first Card in the ArrayList 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 ArrayList.

You must implement the following methods for the Deck class:

initial 45 cards

Important:  The FIRST card in your ArrayList<Card> must be the Ace of Spades, and the LAST card should be the Nine of Stars. Note that in the picture above, the Ace of Spades is at the TOP of the deck, which is to the left.

 

 

 

 

Before cut

initial 45 cards

After cutting by clicking on position 4 (which is the 5th card if you count starting from 1).  (So, we clicked on the 5 of spades, which was at position 4 in the diagram above.)

45 cards after cut

 

Below are two examples of how the shuffle should work:

Example 1 (number of cards evenly divisible by 5):

Before Shuffling

before shuffling evenly size

After Shuffling

after shuffling evenly size

 

Example 2 (two cards short of being evenly divisible by 5):

Before Shuffling

before shuffling two short size

After Shuffling

after shuffling two short size

 

Patrickjack Rules

Read the Patrickjack Page. To successfully implement the Patrickjack evaluation part of this project you need to know the rules of how values are assigned to these hands very precisely so read this information carefully!

HandEvaluatorPatrickjack.java

This class consists of two static methods that you will write. The prototypes for the methods are:


Starfish Poker Hands

Read the Starfish Poker Hand Page. To successfully implement the Starfish Poker hand evaluation part of this project you need to know the definitions of these hands very precisely so read this information carefully!

HandEvaluatorSFCP.java

This class consists of several static methods that you will write. Each method can assume that the array passed into it has exactly 5 elements. The prototypes for the methods (in the order we think you should work on them) 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 Nine).  If you need to review the various "poker hands" being tested in the methods, please take another look at the Starfish 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, Nine of Spades, Nine 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 or five-of-a-kind do not also count as two pair. 
For example, if the current hand is:

<2 of diamonds, 2 of stars, 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 HandEvaluatorSFCP class and at least three eval scenarios for the HandEvaluatorPatrickjack class. Your tests should be as thorough as possible. Be sure that for each HandEvaluatorSFCP method you have written some tests where the method returns "true", and some tests where the method returns "false".

5% of your grade on this project will be determined by the thoroughness of the tests you write. Please note that in order to get any credit for a JUnit test, your project must pass the test AND it must be a proper test of what we have requested. You will place your JUnit test methods into the file provided called "StudentTests.java" in the p6Testing package. If the tests are not located in this file in this package, you will not get credit for them.

 

Requirements


Project Submissiong

Submit your project from Eclipse by right-clicking the project folder and selecting "submit project". You may incrementally submit as many times as you feel is useful since we will only grade the submission that scores the highest on the automated tests. Remember, after you have submitted your project, you should visit the submit server. As always, you will be able to obtain some feedback about how well your project is performing. Again, as usual on projects, the number of times you can run our release tests on your project (before the due date) is limited. The earlier you begin working on the project, the more opportunities you will have to see how your project performs on our release tests before the due date!

 

Running the Deck Simulation

To run the simulation execute the main method in the Launcher.java class. This will allow you to do simple testing of building a deck, cutting the deck, and dealing a single card from the deck. You can cut the deck by clicking somewhere in the middle of the deck. Deal is accomplished by clicking the button. However, this is limited and most testing should be done via JUnit and the submit server.

 

Grading

Please note, there are public tests and release tests for both things related to the Deck and things related to hands. It is strongly suggested that you run the Release tests when you think you are done with your Deck (for example) rather than waiting until all of the Public tests (for both deck-related and hand-related things) are passing. The submit server for this assignment will allow you to run the Release tests even when some Public tests are still not passing.

Your grade will be computed as follows with the exception being that if any of the classes violate the rules given above, we will go in and remove submit server points connected to any class that was not written according to the restrictions stated about things like arrays and ArrayLists.





Web Accessibility