The game of Pig is a simple two player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn a player rolls a six-sided die. After each roll:
•If the player rolls a 1, then the player gets no new points and it becomes the other players turn.
•If the player rolls 2 through 6, then he can either:
•ROLL AGAIN or
•HOLD. At this point the sum of ail rolls is added to the players score and it becomes the other player's turn.
Write a program that plays the game of Pig, where one player is a human and the other is the computer. When it is the humans turn, the program should show the score of both players and the previous roll. Allow the human to input “r” to roll again or “h” to hold.
The computer program should play according to the following rule:
•Keep rolling when it is the computers turn until it has accumulated 20 or more points, then hold. If the computer wins or rolls a 1, then the turn ends immediately.
Allow the human to roll first. The following line of code can be used to generate a random number between 1 and 6 that can correspond to the dice roll:
![]()
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.