CS 312 Assignment 7, Pig (Dice Game) Simulation
Programming Assignment 7: Individual Assignment. Pair Assignment. You must complete this assignment by yourself or with one other person. The other person must be in Mike's CS312 sections. You cannot work with a student from Dr. Nandakumar's sections of CS312. You may not copy solutions from other pairs, past students, or the world wide web. You are encouraged to get help from the instructional staff.
You may work with one other person (You make work with one other person on this assignment using the pair programming technique.. Read this paper on pair programming. You may work with anyone in the class. They do not have to be in the same discussion section as you. One solution will be turned in for the pair. Once you start working with one partner on an assignment you may not switch partners. If you do not wish to work with a partner after starting on an assignment you must both complete it individually. The intent here is you work on the assignment together, at the same time, at the same computer. Do not simply try to work on different parts independently and then try to put it together.)
Placed online: Tuesday, October 15
20 points, ~2% of total grade
Due: no later than 11 pm, Thursday, October 24
General Assignment Requirements
The purpose of this assignment is to implement a program that plays the simulates the dice game of Pig. To do the program you will practice the following techniques.
Description: Pig is a dice game between two players. The Wikipedia article summarizes the rules nicely:
"Each turn, a player repeatedly rolls a die until either a 1 is rolled or the player decides to "hold"
The first player to score 100 or more points wins."
You can play a version of the game against a computer player that plays optimally at this site.
Strategies: There are various strategies for how to approach the game. The decision a player has to make after each roll, if it is not a 1 and the turn is over, is whether to hold and take the points for the turn or roll again to try and get more points for the turn. The strategies you implement will depend on the points so far for the turn, the number of successful rolls for the turn, the difference between players' scores, or some combination of those factors. Obviously if a player's score plus their points for a round are greater than or equal to the goal, normally 100, the player should hold and win the game.
Implement a total of three strategies. Two of the strategies are given. You create the third strategy.
First Given Strategy: Roll until the total for the turn is 15 or greater. In this strategy if the die roll was not a 1, compare the current point total to the turn to 15. If the point total for the turn is less than 15 roll again. If the point total for the turn is greater than or equal to 15, hold and end the turn.
Second Given Strategy: Roll until 5 successful rolls are made in the turn. In this strategy the player ignores the current point total for the turn and instead looks at the number of successful rolls made so far this turn. If the number of successful (non 1) rolls this turn is less than 5 the player rolls again. If the number of successful (non 1) rolls this turn is 5 the player holds.
Your Strategy: You must devise a third strategy. Do not search the web for a strategy and implement it. You must come up with the strategy on your own. Do not simply change the required score from strategy 1 or the required number of rolls from strategy 2. Do not simply combine those strategies. Do something creative and / or effective. You may consider the score for the turn and the number of rolls for the turn, but also consider things like the difference between players' scores, the number of points needed to win, and so forth. Part of your grade will depend on the creativity and / or effectiveness of your strategy. (In other words creative strategies, that are not effective will get full credit and effective strategies will also get full credit.)
Output: Your program must produce the same output as the sample output. This is possible because even though we are using a Random object, if a Random object is given the same initial seed value, in this case 2000316, the numbers produced by the Random object will be exactly the same.
Note, the complete program runs 2 games with output and then 4,000,000 games with no output. My version of the program takes about 30 seconds to complete the simulation of 4,000,000 games.
Write-up: Look at the questions in PigQuestions.txt. Run the necessary experiments and answer the questions. Part of your grade depends on how complete and thoughtful your answers to the questions are.
Approach: You are not using anything new in this program other than the Random object and its nextInt() method. The rest is review of the programming techniques you have already learned: output, variables, parameters, definite and indefinite loops, parameters, conditional execution, methods for structure and to remove redundancy. As always you will graded on how well written your program is in addition to the correctness of the output.
When finished turn in your
completed program named
PigSimulation.java using the
turnin program. If you are working
with a partner turn in the file to only one person's account. if you are
working with a partner you MUST fill in the header correctly or the other
person will not get credit for the assignment. DO NOT TURN IN THE PROGRAM TO
EACH STUDENT'S ACCOUNT. TURN THE PROGRAM IN TO ONLY ONE PERSON'S ACCOUNT. If
you use slip days each student MUST have the required number of slip days or
the assignment is a zero for both students.
Checklist: Did you remember to:
Back to the CS 312 homepage.