CS139 Algorithm Development

Software Requirements Specification

Programming Assignment 6

The Many Player Game of Rats!

Rats!

Due Wednesday Dec 2, by 11:00pm



Introduction

Purpose: The game of Pig is a dice game played with two dice.  This game, Rats!, is a variant of that game played with human or computer players. In the game, players take turns throwing two dice.  They keep score using the face value of the dice. The first player to reach 100 points wins.  On each turn, the player may throw both dice and record the number of points shown on the dice.  They can choose to continue to throw the dice or relinquish their turn to the next player.  If they relinquish the dice, the total number of points for that turn are added to their overall score.  If they hog the dice (be a Rat) and throw "Rat's Eyes" (double 1), then they lose all of the points that they accumulated that turn. Anytime Boxcars (double 6's) are thrown, accumulated points are added to the total score for that player and the player must relinquish their turn.  Play continues until one player reaches 100 points.  If the first player reaches 100 points, the second player does not get a turn. 

Objectives - At the conclusion of this exercise the student will demonstrate that they can:

Deadlines

Prerequisites

You have covered the material about classes and objects in Gaddis, Chapter 6, 8 and 9. 

Application Structure

Your application will consist of a number of different classes each with its own specific purpose.  More detail will follow below - See the links for the "Starters" for all programs.

Rats - Will set up the game and call the playGame method.
RatGame - Will carry out the actions of game play.
Player - Holds the name and the score for each player.  
RatDice - This class is provided for you and contains the methods to get the sum of the thrown dice and to see if RatsEyes or Boxcars are thrown.

Application Behavior

  1. The application announces the game.  (see output below for all output statements).
  2. The application requests from the user the number of players. 
    1. If a non-integer value is entered, display an error message and reprompt the user.
    2. If a negative number is entered, display an error message and reprompt the user.
  3. The application requests from the user the names of each player and creates a Player object for each one.
    1. If only one player, ask for the name for player 1, and then create a human player and a computer player. (The computer's name is "HAL").
    2. If more than one player, ask for the name for each player, and create as many Player objects as you need.
  4. The application than creates the game and begins play.
  5. To determine who starts, each player in turn throws the dice starting with player 1.  The player with the highest roll goes first.  Play rotates among the players between each game.  For example, if we have a human and computer player ("Dave" and "HAL"), if Dave rolls higher, he goes first in game one, second in game two, first in game three, etc.  If there are three players, "Dave", "Henry", and "Jane", if Henry goes first in the first game, Jane would go first in the second and Dave goes first in the third.  In case of two or more players rolling the same highest number, all players rethrow the dice until one player has a high throw. Announce each throw and who is going first.
  6. Throw the first dice for the first player and announce the roll.  If the player is the human player, ask if they want to throw again.  Continue throwing until:
    1. the user says that they want to relinquish the dice.  (Y or yes or any variant of these).  All accumulated points in this turn are added to their total points.
    2. RatsEyes are rolled.  All accumulated points are lost.
    3. Boxcars are rolled.  The boxcar points are added to the turn points and then turn points are added to the accumulated points.
    4. Turn points + accumulated points reach or exceed 100 for this player.
    If the player is the computer player, continue to throw until:
    1. the computer accumulates more than 20 points in this turn.
    2. RatsEyes are rolled.  All accumulated points are lost.
    3. Boxcars are rolled.  The boxcar points are added to the turn points and then turn points are added to the accumulated points.
    4. Turn points + accumulated points reach or exceed 100 for this player.
  7. Repeat step 6 for the each subsequent player.
  8. Repeat steps 6 and 7 until one of the player wins.
  9. Announce the winner and the points accumulated by all players.
  10. Ask if the players want to play again.
  11. If yes or y (ignoring case), reset all points totals to zero for both players.  Resume play at step 6.  (See step 5 for alternating turns).
  12. If no, thank the players for playing and exit.

Output Statements

Program Behavior
Reference
Output printf statement parameter 1 parameter 2 parameter 3 parameter 4
1 "Welcome to the game of Rat\n\n"
2 "How many players today? "
2 "\n" - After reading in the value.
2.a "Bad value %s\n" bad input value
2.a "This is not an integer.  Try again.\n"
2.b "Please enter a positve number. Try again.\n"
3 "What is the name of player %d: "  The number of this player, beginning with player 1
3 "\n" - After reading in the value.
5 "%s rolls %d-%d\n" (this for each player)

%s goes first\n" OR TIE throw again\n" - if more than one player throws the same value.
player name and throw
(throws will always be shown as x-y where x is die one and y is die two)
The name of the first player to go (or nothing if tie)
6 and 7 "%s rolls %d-%d\tturn %d total %d\n" OR "%s rolls %d-%d - RATS! total %d\n" OR "%s rolls %d-%d - BOXCARS! turn %d total %d\n" - The first is for most rolls, the second for RatsEyes and the third for a roll of Boxcars. player name throw turn accumulated points (not used for RatsEyes) total points including the turn total
6.a "Give up the dice? "
6.a "\n"- After reading in the value.
9 "\n%s WINS!\n" winning player name
"\t%s points %d\n" (You will have one of these lines for each player) player name player total points
10 "Do you want to play again? "
10 "\n"- After reading in the value.
12 "Thanks for playing RATS! Good bye\n"

Toolkit changes

You should use your toolkit to verify the number of players for the game.  There are no changes required.

Additional Program Requirements

  1. The RatGame constructor requires a seed value for the random generator used in the RatDice class.  This seed will come through as a command line argument.  (See book Chapter 8.12 or hardcode one in your RatDriver and come to class on Monday Nov 16 for more information).
  2. You will use the starter classes for RatGame and Player provided.
  3. You may NOT use recursive method calls to playGame.  Instead, playGame should loop for successive games.
  4. All input and output will be done in RatDriver, RatGame, and Toolkit except for the question about taking another turn which is done in the player goAgain method.
You must use the programs as stated above.  You may not make any changes to the RatDice class.

Honor Code

This work must conform to the JMU Honor Code and the specific requirements of this class. NO help may be provided by any student to another student. Authorized help is limited to your textbook, the TAs for any CS139 or CS239 section, and the professor for your section. See collaboration policy.

Grading

        For submissions after:

HINTS

  1. Work and test this code in pieces.  Make the Player class and use a test driver to test each of the methods, constructor, toString, and each of the methods involved in game play.  Then work through the game, only playing one game.  When one game is working properly then add in the code for multiple games and the alternating starting players.
  2. Alternating turns can be accomplished by having a turn counter which increments for each player and loops to the first player when the top player is reached.
  3. You must use a single keyboard Scanner object (System.in) for this problem.  Using multiple Syste.in Scanner objects (calling the Scanner constructor with System.in multiple times) will result in a failure to read all of the input in submit.
  4. Stub out your code and build each method individually.
  5. You should build in extra printlns to use in debugging your code.  You can always comment these out or condition them with a DEBUG variable.
  6. Start with the provided code.  We have built the shell of the RatGame and Player classes that you will use.  
  7. To control the tests, build a small program that will generate the random numbers needed in this program.  Use different seeds to generate different patterns that will allow you to test each player going first, RatsEyes, boxcars, etc.  See class notes from Monday Nov 16 for more information.
  8. Begin early.  Students run into trouble by waiting too long to start the program. 
  9. Understand the problem at hand.  Make sure that you follow the requirements precisely.  Don't add additional "flourishes".  You will be downgraded.
  10. Play the game with a friend before you design your code to understand how the game will work.  (This does not violate the honor code even if the two players are in this class.)
  11. In the body of your main method, outline your steps with comment lines for each part of the project.  Do the same with each of the other methods.
  12. If you wish to use additional methods to break up your code, feel free to do so.  If you wish to add additional classes, feel free to do so.