Pig is a folk jeopardy dice game with simple rules: Two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 ("pig") is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn, the player is faced with two decisions:
Problem: Simulate a single solitaire game of Pig where a player rolls until a 1 ("pig") is rolled, or the turn total is greater than or equal to 20, or the score plus the turn total is greater than or equal to 100.
Input Format: (no input)
Output Format:
Sample Transcript:
Roll: 4 Roll: 6 Roll: 1 Turn total: 0 New score: 0 Roll: 6 Roll: 5 Roll: 5 Roll: 6 Turn total: 22 New score: 22 Roll: 6 Roll: 2 Roll: 2 Roll: 3 Roll: 3 Roll: 2 Roll: 5 Turn total: 23 New score: 45 Roll: 3 Roll: 4 Roll: 6 Roll: 2 Roll: 6 Turn total: 21 New score: 66 Roll: 3 Roll: 3 Roll: 4 Roll: 4 Roll: 6 Turn total: 20 New score: 86 Roll: 3 Roll: 5 Roll: 5 Roll: 6 Turn total: 19 New score: 105
Common Error: When creating nested loops, perform loop initialization directly before the relevant loop. Note:
<loop 1 initialization>
<loop 1>
<loop 2 initialization>
<loop 2>
is not the same as
<loop 1 initialization>
<loop 2 initialization>
<loop 1>
<loop 2>
In the latter case, <loop 2> is not properly initialized each time.