|
CS 139
Algorithm Development
Part A - There is no Part A for this assignment. Part B Due in WebCAT by Wednesday, November 5 at 11:59 PM
Part D due in class on Friday, November 7 or one day after you have successfully submitted to WebCAT. |
---|
The game of Pig has many variants. In this variant, a single die is used to play a game between the human and the computer. The goal is to be the first to reach 100 points by rolling the die. A player may choose to roll the die any number of times. Each time the die is rolled the value of the die face is added to the player's turn score. If a player relinquishes the die to their oponent, all turn points are added to the person's bank. As soon as the points in the person's turn and their bank reach 100 points, that player wins. The catch in all of this is that if a 1 is rolled, the player loses all of their turn points and play automatically passes to the other player. So the idea is to not be too "piggy" and "hog" the die, but to relinquish control when there are "enough" points in the turn to bank.
In this assignment, you will use a Random object as the "die" which will produce random numbers in the range of 1-6 to represent the die faces. Each player will use this same die.
Player 1 will be a human player and will always go first. Player 2 will be the computer and will always go second. The goal of the human player is to beat the computer player.
You will write a Java program consisting of PigDriver and Pig.java, that must:
See the sample dialog found here: GameDialog.txt
Special requirements: A roll of 1 is poison. If the die roll is a 1, then the player who rolled that die will lose all of their turn points. If a player chooses to end their turn (the computer at 12 or more points, the human by choosing n), the turn points go into their total score bank and cannot be lost. For example, if a player took a turn and accrued 12 points, then relinquished their turn to the computer, those 12 points become part of the permanent score. If the player takes another turn and accrues 15 points and then throws a 1, they lose the 15, but they still have the 12 from the prior turn.
PA4.java is being given to you. It will bring a seed value in as a command line argument. See RandomLesson in the material for this unit and the demo in class. It will create a Random generator and pass that generator to PigGame's playGame method.
A PigGame starter is being given to you. PigGame.java has some "global variables" or in object terms, these are known as attributes. Since they are defined inside the class but outside of any method, their scope is to be visible in any method. So for example, when you want to add the turn points to the player's score, you will use the playerScore variable. These attributes are all initialized to 0 or null for reference types.
PigGame will have the following required methods:
public void playGame(Random randGen) - controls the action of the game. It takes in a Random object and returns nothing. It should instantiate the Scanner object so that one Scanner can be used throughout the game.
You may add additional methods to PigGame.java.
You will write a reflection document for this assignment which will let you consider the process of building this program. It will also contain a place to critique this assignment for this class.
In addition, you should keep a log showing how much time you and your partner worked together and how much time you worked alone.
This is a pair programming assignment. You may work with your partner, but may not work with any other team. This assignment should be viewed as a take home exam. Your work on the assignment and your submission must conform to the JMU Honor Code. Authorized help is limited to the classroom handouts, lab material, the TAs for any CS139 or CS 149 section, and either professor. Copying work from another student not in your partnership or the Internet is an honor code violation, which will result in a zero on the assignment and possibly further sanctions. Your work on this assignment is subject to review by MOSS which is a plagiarism detection tool for programs. Submission to WebCAT constitutes your submission of work for academic credit and your agreement that your work may be submitted to MOSS.