Python Forum
Two Dice Pig Game in Python 3.6 Help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Two Dice Pig Game in Python 3.6 Help
#1
Here are the instructions...


Write a Python program to simulate the Two Dice Pig game. Two Dice Pig is played by 2 players who roll 2 standard dice to earn points.
The object of the game is to be the first player to score 100 or more points.
For our game, player 1 will be a human player, and the 2nd player will be the computer. Each player's roll will be randomly generated by the program. The human player (player 1) gets to choose whether they want to roll again or not after each roll time they roll. When they choose
not to roll again, it is called a "hold". The computer (player 2) doesn't get that choice and automatically rolls again every time until a 1 is rolled by the computer.
Here are the detailed game rules: For each player's turn, a player repeatedly rolls two standard dice until a 1 is rolled, or in the case
of the human player (player 1) that player decides to hold. After each roll of the two dice, the roll determines what happens next based on the following rules:

If neither die shows a 1, the sum of the two dice is added to the player's total. The computer automatically rolls again. The human player (player 1) rolls again if they decide they don't want to hold.

If a single 1 is rolled, the player scores nothing for this roll and the turn ends.

If two 1s are rolled, the player’s entire score is lost, and the turn ends.
Hint:
You will want to have a turn variable that will keep up with if it is player 1's turn or player
2's turn. For example, turn should equal 1 when it is player 1's turn and then change to 2 when it's player 2's turn and vice versa.





I have wrote some code and it isn't correct.
It plays the first round, but then when you roll again, it generates the same random numbers. I am not sure how to fix this.
I am also not sure how to keep track of the total score after every round.

I also haven't been able to figure out how to deal with the 1's being rolled and losing the scores when they are rolled.


Here is my code as of now...


import random
def main():
    
    
    print("Welcome to the Two Dice Pig Game. You are Player 1!")
    
    
    p1dice = random.randrange(1,7)
    p1dice2 = random.randrange(1,7)
    p2dice = random.randrange(1,7)
    p2dice2 = random.randrange(1,7)
    Player1 = p1dice+p1dice2
    Player2 = p2dice+p2dice2
    
    while(Player1<100 or Player2<100):
        
        
        print("Player 1 dice 1 =",p1dice)
        print("Player 1 dice 2 =",p1dice2)
        print("Player 1 dice total =",Player1)
        print("Does player 1 want to hold?")
        choose1 = input("Enter y for yes or n for no.")
        if(choose1=="n"):
            print("Player 1 dice 1 =",p1dice)
            print("Player 1 dice 2 =",p1dice2)
            print("Player 1 dice total =",Player1)
            print("Does player 1 want to hold?")
            choose1 = input("Enter y for yes or n for no.")
        elif(choose1=="y"):
            
            print("It's player 2's turn.")
            print("Player 2 dice 2 =",p2dice)
            print("Player 2 dice 2 =",p2dice2)
            print("Player 2 dice total =",Player2)
            print("Does player 2 want to hold?")
            choose2 = input("Enter y for yes or n for no.")
        
    
    
    
    
main()
Reply


Messages In This Thread
Two Dice Pig Game in Python 3.6 Help - by inspired22 - Oct-10-2018, 04:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need some help with Dice Game for daughter in school OptX 2 1,945 Feb-12-2021, 08:43 PM
Last Post: BashBedlam
  regarding dice game hola123 4 2,370 Feb-10-2021, 11:00 PM
Last Post: hola123
  Two dice Game of Pig help elliemehl 2 4,229 Feb-14-2019, 01:19 AM
Last Post: woooee
  help with while loop on dice game sean5 2 4,197 Dec-14-2017, 07:24 PM
Last Post: nilamo
  dice game im stuck sylerr 3 4,433 May-12-2017, 10:50 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020