Chuck-a-luck

Introduction

Chuck-a-luck is a betting game played with three dice. The player puts his or her money down on one of the possible bets, then the dealer rolls the dice. The player collects a payout if the outcome matches the bet. A playable online version for understanding the problem is located here: http://the-chaos.com/cgi-bin/chuck-a-luck.cgi

The following table describes the possible bets:

Type Bet Odds
Single A specific number will appear on at least one die 1 dice, 1 to 1
2 dice, 2 to 1
3 dice, 10 to 1
Any Triple Any of the triples (all three dice show the same number) will appear 30 to 1
Big The total score will be 11 or higher with the exception of a triple 1 to 1
Small The total score will be 10 or lower with the exception of a triple 1 to 1
Field The total score will be outside the range of 8 to 12 (inclusive) 1 to 1

The final column in the table describes the payout if the player wins the corresponding bet. For example, if a player puts $5 down on single 3, and roll is [3, 3, 2], the payout will be $10 because the odds for that outcome are 2 to 1. If the dice rolled are [3, 3, 3], then the payout will be $50, because the odds for that outcome are 10 to 1.

Your goal for this assignment is to develop and test a method for determining payouts in Chuck-a-luck.

Provided Code

Start with the following source files:

 

Dice.java

The Dice class represents a complete set of three rolled dice. Dice objects provide several methods:

  • getFirst, getSecond, getThird - These methods make it possible to access the numbers showing on each of the individual dice.
  • addValues - This method adds the numbers showing on the three dice and returns the result.
  • countValues - This method counts the number of times a particular number shows on the three dice. For example, if the dice are [1, 3, 3], dice.countValues(3) will return 2 (since the value 3 occurs twice).

Here is a code snippet that illustrates these methods:

Dice dice = new Dice(4, 2, 4); // Create a set of dice with 4, 2, and 4 showing

System.out.println(dice.getFirst());     // 4 will be printed

System.out.println(dice.getSecond());    // 2 will be printed

System.out.println(dice.getThird());     // 4 will be printed

System.out.println(dice.addValues());    // 10 will be printed (10 = 4 + 2 + 4)

System.out.println(dice.countValues(1)); // 0 will be printed. (zero 1's) 

System.out.println(dice.countValues(4)); // 2 will be printed. (two 4's) 

Driver.java

The file Driver.java contains the implementation of a simple terminal-based Chuck-a-luck game. This code includes all of the game logic except the payout method. Once you have completed ChuckALuck.java you can use this driver to try out your code.

Since this driver generates random dice rolls, it will not be very useful for systematically testing your solution. The main mechanism for running your code for this project will be the ChuckALuckTest.javafile described below.

ChuckALuck.java

Your main task for this assignment is to implement the ChuckALuck.calculatePayout method according to the provided documentation string. For full credit, your finished method must satisfy the following requirements:

  • A switch statement must be used to distinguish between the different bet types.
  • Appropriate helper methods must be used to break the problem into smaller and more manageable pieces.
  • Your code must make use of the named constants declared at the top of the ChuckALuck class. Avoid the use of hard-coded literal values in your solution.
  • Your ChuckALuck.calculatePayout method must have only one return statement.

ChuckALuckTest.java

You must write JUnit tests for ChuckALuck.java. Rather than writing one very long testCalculatemethod, you should write several smaller methods to handle distinct cases. The provided file contains two testing methods to get you started:

   
    /**
     * testCalculatePayoutSingleNoMatch.
     */
     
    @Test
    public void testCalculatePayoutSingleNoMatch() {
        Dice dice = new Dice(1, 2, 3);

        double expected;
        double result;

        result = ChuckALuck.calculatePayout(dice, ChuckALuck.SINGLE, 4, 100.0);
        expected = -100.0;
        Assert.assertEquals(expected, result, .0001);

        result = ChuckALuck.calculatePayout(dice, ChuckALuck.SINGLE, 5, 200.0);
        expected = -200.0;
        Assert.assertEquals(expected, result, .0001);

        result = ChuckALuck.calculatePayout(dice, ChuckALuck.SINGLE, 6, 300.0);
        expected = -300.0;
        Assert.assertEquals(expected, result, .0001);

        result = ChuckALuck.calculatePayout(dice, ChuckALuck.SINGLE, 6, 0.0);
        expected = 0.0;
        Assert.assertEquals(expected, result, .0001);

    }

    /**
     * testCalculatePayoutSingleOneMatch.
     */
@Test public void testCalculatePayoutSingleOneMatch() { Dice dice1 = new Dice(4, 5, 6); // We'll try each of 4,5,6 as a single Dice dice2 = new Dice(1, 1, 2); // Confirm duplicates don't cause errors double expected; double result; result = ChuckALuck.calculatePayout(dice1, ChuckALuck.SINGLE, 4, 100.0); expected = 100.0; Assert.assertEquals(expected, result, .0001); result = ChuckALuck.calculatePayout(dice1, ChuckALuck.SINGLE, 5, 200.0); expected = 200.0; Assert.assertEquals(expected, result, .0001); result = ChuckALuck.calculatePayout(dice1, ChuckALuck.SINGLE, 6, 300.0); expected = 300.0; Assert.assertEquals(expected, result, .0001); result = ChuckALuck.calculatePayout(dice1, ChuckALuck.SINGLE, 6, 0.0); expected = 0.0; Assert.assertEquals(expected, result, .0001); result = ChuckALuck.calculatePayout(dice2, ChuckALuck.SINGLE, 2, 300.0); expected = 300.0; Assert.assertEquals(expected, result, .0001); }

Notice that the names of these methods describe the situations they are designed to test:

testCalculatePayoutSingleNoMatch

  • test - This makes it clear that this is a testing method
  • CalculatePayout - This is the method being tested
  • SingleNoMatch - This is the situation being tested.

 

You should properly document your tests(less detail required here) and your ChuckALuck.java file.

Autolab will automatically evaluate your JUnit tests on the basis of statement coverage. Your tests must be written so that every line of code in ChuckALuck.java is executed during at least one test.

Categories you should test include(this is a template for your ChuckALuckTest.java file):

  • Test payout single no match
  • Test payout single one match
  • Test payout single two match
  • Test Triples match
  • Test Triples no match
  • Test payout BIG match
  • Test payout BIG no match
  • Test payout SMALL
  • Test payout SMALL no match
  • Test payout field match
  • Test payout field no match

 

Part A - Tests and Readiness Quiz(50 points)

This includes two portions:

1) Readiness Quiz(10 points) in Canvas.

2) Tests (40 points) submitted to (10 points) Autolab.cs.jmu.edu

Before the deadline for Part A you should read this document carefully, then look at the starter code provided above. Once you have a clear understanding of the expectations for this assignment, complete the readiness quiz in Canvas(10 points). The grading for this quiz will be all or nothing: your score on the quiz will be 0 if you miss any questions. If you do not successfully complete Part A, you cannot receive any credit for Part B.

Part B(50 points)

Upload a .zip file containing both ChuckALuck.java and ChuckALuckTest.java. You should not include Driver.java or Dice.java in your submission.

Before uploading your submission to Autolab.cs.jmu.edu, be sure to complete the following steps:

  • Test your solution carefully. Make sure that Driver.java works as expected with your finished code.

  • Review the course style guide to ensure that your code meets the style requirements.
  • Run Checkstyle and eliminate all warnings. Review and update comments as needed.

Your submission will be graded using the following criteria:

Points
Part A quiz  10
Part A Tests 40
Part B Code 25
Part B Style and tests 15
Part B Instructor points 10

The Autolab grading for this assignment will be based both on the correctness of ChuckALuck.java and on the quality of the tests in ChuckALuckTest.java. Autolab will test each of the following:

  • ChuckALuck.java must pass all instructor-provided tests.
  • ChuckALuck.java must pass all of the tests that you provide.
  • The tests in ChuckALuckTest.java must cover all lines of code in ChuckALuck.java.

If Autolab deducts any points for correctness/testing, you will receive at most 25/50 on that component of the score.

Honor Code

This assignment must be completed individually. Your submission must conform to the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 149, and the instructor. Copying work from another student or the Internet is an honor code violation and will be grounds for a reduced or failing grade in the course.

Acknowledgments

This assignment is based on the original Chuck a Luck designed by Nathan Sprague which was loosely based on a similar Yahtzee project developed by Chris Mayfield and others. Some parts of the Chuck-a-luck description above are borrowed from the Chuck-a-luck Wikipedia page. The Wikipedia article, and this assignment page, are licensed under the Creative Commons Attribution-Share-Alike License 3.0.

Back to Top