Difference between revisions of "CISC181 S2017 Lab7"

From class_wiki
Jump to: navigation, search
(Submission)
Line 7: Line 7:
 
==Instructions==
 
==Instructions==
  
Suppose you want to write a Poker game app based on the <tt>Card</tt> and <tt>Deck</tt> classes introduced earlier in the semester.  Obviously, a core function would be to ''compare'' two hands and determine which one is better.
+
Suppose you want to write a Poker game app based on the <tt>Card</tt> and <tt>Deck</tt> classes introduced earlier in the semester (see [https://drive.google.com/open?id=1DnSnRiRXdtWQTfcNAKarvhHifePBbj_2RGuVC9pORBk lecture 11] for code).  Obviously, a core function would be to ''compare'' two hands and determine which one is better.
  
In this lab you will write a <tt>Comparator</tt> class <tt>ByHandValue</tt> to compare hands in ''5-card draw'' Poker, again using test-driven development like last week.  The comparison function will be <tt>int compare(ArrayList<Card> H1, ArrayList<Card> H2)</tt>, where a return value < 0 indicates that H1 would lose to H2, a return value > 0 means that H1 would beat H2, and a return value of 0 means H1 and H2 are "tied."
+
In this lab you will write a <tt>Comparator</tt> class <tt>ByHandValue</tt> to compare hands in ''5-card draw'' Poker, again using test-driven development like last week.  The comparison function will be <tt>int compare(ArrayList<Card> H1, ArrayList<Card> H2)</tt>, where a return value < 0 indicates that H1 would lose to H2, a return value > 0 means that H1 would beat H2, and a return value of 0 means H1 and H2 are "tied." You '''must''' use the <tt>Card</tt> class provided -- do not make your own.
  
 
The ranking of hands is detailed [https://en.wikipedia.org/wiki/List_of_poker_hands here].  Assume that cards come from a standard 52-card deck with no wildcards, and aces can be high or low.
 
The ranking of hands is detailed [https://en.wikipedia.org/wiki/List_of_poker_hands here].  Assume that cards come from a standard 52-card deck with no wildcards, and aces can be high or low.

Revision as of 15:34, 10 April 2017

Preliminaries

  • Make a new project with n = 7 (following these instructions)
  • Name your main class "Lab7" (when creating a new module in the instructions above, in the Java class name field)

Instructions

Suppose you want to write a Poker game app based on the Card and Deck classes introduced earlier in the semester (see lecture 11 for code). Obviously, a core function would be to compare two hands and determine which one is better.

In this lab you will write a Comparator class ByHandValue to compare hands in 5-card draw Poker, again using test-driven development like last week. The comparison function will be int compare(ArrayList<Card> H1, ArrayList<Card> H2), where a return value < 0 indicates that H1 would lose to H2, a return value > 0 means that H1 would beat H2, and a return value of 0 means H1 and H2 are "tied." You must use the Card class provided -- do not make your own.

The ranking of hands is detailed here. Assume that cards come from a standard 52-card deck with no wildcards, and aces can be high or low.

You should throw a PokerException if either H1 or H2 does not have exactly 5 cards, or if any of the cards are duplicates (either within or between hands).

This time, JUnit is required. Once again, you should create a suite of unit tests that make various hands and see if compare() works as it should. As, before, this is what your main() should contain:

Result result = JUnitCore.runClasses(HandComparisonTests.class);
for (Failure failure : result.getFailures())
  System.out.println(failure.toString());

We will grade your lab strictly by how many of the N unit tests in our grading suite are passed. Since you can get compare() right 1/3 of the time just by chance, your lab score will be determined by a linear map from [N/3, N] tests passed to a score of [0, 4].

Submission

Submit your ByHandValue.java and HandComparisonTests.java on Sakai (be sure to add your name and section number to both). Do NOT submit Lab7.java.