Program #3 Filename: pig . PIG is played with a standard six-sided die and proceeds as follows: Each player starts with zero points, and the rst to...
View the step-by-step solution to:

Question

# Program #3Implement dice game called PIG,

pitting two human players against each other. PIG is played with a standard six-sided die and proceeds as follows:

● Each player starts with zero points, and the first to 20 points wins.

● The current player chooses to roll or hold.

● If they choose roll:

○ The six-sided die is rolled

○ The value of the die is added to their round points.

○ The player goes again UNLESS...

○ ...If the value on the die is 1, then the round is over and the player has lost all the points they accumulated in the round.

● If they choose hold:

○ The points accumulated in the round are added to the player's overall score.

○ The round is over.

● When the round ends (either because the player rolled a 1 or they chose to hold), it becomes the other player's turn unless somebody has won.

● We check to see if someone won at the end of each round (which is kind of unfair, because if Player One gets 20 points on the first round, then Player Two never gets a chance, but oh well tough for them).

Requirements:

● each player to either R (roll) or H (hold).

● If they enter anything else, continue prompting them until they enter a correct input.

● On a roll, randomly generate a value 1-6 to represent the die.

● End the round when the die roll is value 1 (round points are lost), or the player chooses Hold (round points are added to that player's overall score).

● End the game one either player has 20 or more points and announce the winner.

● Report everything as you go along -- what the die roll was, number of points so far, etc.

● As always with your CS5001 programs, your input/output must be friendly and informative.

Python has a random module that can help you generate random numbers. You probably want to import random for this part of the assignment and call randint(...)

import random # near the top of your file random.randint(1, 6) # or something like this in your program

AMAZING points:

● Allow them to enter upper or lowercase letters. R/r for roll, and H/h for hold.

● Make your code extensible enough that we could add an arbitrary number of players with minimal coding-pain. (Consider using a list to store the player names and another list for the number of points each player has.)

Program #3 Filename: pig . py For this assignment, you'll implement a dice game called m, pitting two human players against each other.
PIG is played with a standard six-sided die and proceeds as follows: Each player starts with zero points, and the ﬁrst to 20 points wins.
The current player chooses to roll or hold.
If they choose roll:
0 The six-sided die is rolled
0 The value of the die is added to their round points.
0 The player goes again UNLESS...
o ...If the value on the die is 1, then the round is over and the player has lost all the points they
accumulated in the round.
If they choose hold:
0 The points accumulated in the round are added to the player's overall score.
0 The round is over.
When the round ends (either because the player rolled a 1 or they chose to hold), it becomes the other
player's turn unless somebody has won.
We check to see if someone won at the end of each round (which is kind of unfair, because if Player
One gets 20 points on the ﬁrst round, then Player Two never gets a chance, but oh well tough for them). Requirements: Prompt each player to either R (roll) or H (hold). If they enter anything else, continue prompting them until they enter a correct input. On a roll, randomly generate a value 1-6 to represent the die. End the round when the die roll is value 1 (round points are lost), or the player chooses Hold (round
points are added to that player's overall score). End the game one either player has 20 or more points and announce the winner. Report everything as you go along -- what the die roll was, number of points so far, etc. As always with your CSSOOI programs, your inputr’output must be ﬁiendly and informative. Helpful hints
Python has a random module that can help you generate random numbers. You probably want to import random
for this part of the assignment and call randint (...) import random # near the top of your 'File
random.randint(1, 6) # or something like this in your program AMAZIN G points: Allow them to enter upper or lowercase letters. Rfr for roll, and Hr’h for hold. Make your code extensible enough that we could add an arbitrary number of players with minimal
coding-pain. (Consider using a list to store the player names and another list for the number of points
each player has.)

A sample run of your program might look something like this (except we set the winning threshold to 10 points
for the example, instead of 20, so it wouldn't go on too long).
actice/pig.py
It is your turn, HUMAN TWO
It is your turn, HUMAN ONE
R - Roll
R - Roll
H - Hold
H - Hold
r
You rolled a 1
You rolled a 6
Wah wah waahh. . . round is over!
Points in this round: 6
R - Roll
H - Hold
You got 0 that round!
It is your turn, HUMAN ONE
R - Roll
r
You rolled a 2
H - Hold
Points in this round: 8
R - Roll
H - Hold
r
You rolled a 5
Points in this round: 5
r
R - Roll
You rolled a 2
H - Hold
Points in this round: 10
R - Roll
H - Hold
h
You got 5 that round!
h
It's over HUMAN ONE WINS! ! ! ! !
You got 10 that round!

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

### -

Educational Resources
• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents