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).
● 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
● 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.)
Recently Asked Questions
- PYTHON PROGRAMMING
- how do I write a program to convert the weight of an object from kg to lbs. (1 kg = 2.2 lbs). The program should allow the user to enter the weight in kg. If I
- Contact Manager COMMAND MENU list - Display all contacts view - View a contact add - Add a contact del - Delete a contact exit - Exit program Command: list 1.