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 #3

Implement 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.


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


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.)



Screen Shot 2019-10-02 at 9.01.08 PM.png


Screen Shot 2019-10-02 at 9.01.18 PM.png

Screen Shot 2019-10-02 at 9.01.08 PM.png

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 first 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 first 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 fiiendly 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.)

Screen Shot 2019-10-02 at 9.01.18 PM.png

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
Enter your choice
Enter your choice
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!
Enter your choice
It is your turn, HUMAN ONE
R - Roll
r
You rolled a 2
H - Hold
Points in this round: 8
R - Roll
Enter your choice
H - Hold
r
You rolled a 5
Enter your choice
Points in this round: 5
r
R - Roll
You rolled a 2
H - Hold
Points in this round: 10
R - Roll
Enter your choice
H - Hold
h
You got 5 that round!
Enter your choice
h
It's over HUMAN ONE WINS! ! ! ! !
You got 10 that round!

Recently Asked Questions

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
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes