Die

 

CS 139 Algorithm Development
PA4: The Game of Pig

Part A - There is no Part A for this assignment.

Part B Due in WebCAT by Wednesday, November 5 at 11:59 PM

  • -10% on Thursday November 6
  • -20% on Friday, November 7
  • -35% on Sunday, November 9
  • -50% on Monday, November 10
  • Not accepted afterwards
Part C due in Canvas by Thursday, November 6 or one day after you have successfully submitted to WebCAT.

Part D due in class on Friday, November 7 or one day after you have successfully submitted to WebCAT.

Updates:

Objectives - At the conclusion of this assignment students will have demonstrated that they can:

Background

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.

Requirements

PART A-There is no part A for this PA.

PART B - Submitted to WebCAT. 

You will write a Java program consisting of PigDriver and Pig.java, that must:

  1. Display a welcome message, "Let's Play Pig"
  2. Display a blank line
  3. Prompt for the name of the human player.
  4. Prompt for the name for the computer player.
  5. Display a blank line.
  6. Display the human player name with the line "%s's turn" where the substitution is the name of the player.
  7. Display a blank line.
  8. Display the prompt, "Roll(Y/N)? ". There is one space after the ?.
  9. If the player answers any variant of Y ("Y" or "y") "roll" the die and display the result. The result should be in the form of :(%s Roll: %d Turn: %d Score: %d\n", name, roll, turn, score), where roll is the value for that die roll, turn is the total points for this turn, and score is the total score for this player for all turns. This result should end with the new line character.
  10. If the player answers the roll prompt with anything other than a variant of Y, turn passes to the computer player.
  11. For the computer player, "throw" the dice and display the result of the roll in the same format as the human player. Since the computer cannot "choose" whether or not to continue, we will use the algorithm that if the computer accrues 12 or more points, their turn is over. Play will return ot the human player at that point.
  12. Play ends when either player reaches 50 points. (There should be no turns after the human or computer player reaches 50).
  13. Display a blank line and then the message "%s wins!" where the substitution is the name of the winning player.

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.

Part B Structure

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:

You may add additional methods to PigGame.java.

Part B Deliverables

  1. Zip your PA4.java and PigGame.java into a zip file. Submit the zip file via Web-CAT (http://webcat.cs.jmu.edu).
  2. Your program will be judged on correctness (80%) and conformance to the StyleGuide (20%). The checkoff chart is found here. Deductions for failing to follow the structure will be taken from the 80% correctness score. There is an increase in penalties for not documenting your methods or failing to include the acknowledgement section in your work.

Part C, D - Reflection and Pair Programming Log - graded as regular homework assignments. There will be separate Canvas Assignments for this.

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.

Honor Code

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.