
# File: assignment1.py
# Author: Rania Alshikhe (501292)
# Email Id: 
# Version: 
# Description: Assignment 1 - a program to play a game of PIG against the computer
# This is my own work as defined by the University's Academic Misconduct policy.
#

###################################################################################################
msg = input(" Would you like to play PIG (y/N)?" )
player_name= input("wonderful, what is your name?")
print("Hi",player_name , "lets start the game")
###################################################################################################################################### 
 # start the game now!
die1 = die2 = 0
ps = 0
cs = 0
pturn_total = 0
cturn_total = 0
choice = input("Would you like to roll or hold (r/h)?:" )
while pturn_total  < 100 and cturn_total < 100:
    print("------------------------Start player turn--------------------------------")
    import random
          # player turn
    
    while choice == 'r' and die1 != 1 and die2 != 1:
                # gnerate two roll dice
                die1 =random.randint(1,6)
                die2 =random.randint(1,6)
                ptotal = die1 + die2 
                
                 
                if die1 != 1 and die2 != 1:
                     print ("Die1 is: ",die1,"Die2 is: ",die2,"Die total is:", ptotal)
                     pturn_total +=  ptotal # update player score
                     print ("Turn total:",pturn_total , "Potential score:",ps + pturn_total)
                     choice = input("Would you like to roll or hold (r/h)?:" )# exit loop
                    
                
                elif die1== 1 and die2 == 1:
                     print ("Die1 is: ",die1,"Die2 is: ",die2,"Die total is:", ptotal)
                     print("*** Ouch! That hurts! Two ONEs - you lose your entier score ")
                     print("player score:",pturn_total,"computer score:",cturn_total)
                     choice = input("Would you like to roll or hold (r/h)?:" )# exit loop

                elif die1== 1 or die2 == 1:
                     print ("Die1 is: ",die1,"Die2 is: ",die2,"Die total is:", ptotal)
                     print(" *** You rolled a ONE turn over - no point for you! ")
                     print("player score:",pturn_total,"computer score:",cturn_total)
                     choice = input("Would you like to roll or hold (r/h)?:" )# exit loop     
                     
                else:     

                     potential_score >= 100
                     print("you win! Congratulations!")
                     choice = input("Would you like to roll or hold (r/h)?:" )# exit loop
                     
    # when player choose hold
              
    if choice == 'h':
        print("\n|*** Hold!\n| ")
        cs = 0
        print("player score:",pturn_total,"computer score:",cs)

    else:
        
        choice != 'r' and choice != 'h'  # invalid choice
        print ("| Invalid input, please try again.")
        choice = 'r'
                   

    print("-----------------------------------------END player turn----------------------------------")
                                  
    #########################################################################################################################################################################
    print("--------------------------------------------START computer turn----------------------------")
    choice = "q"      
    die1 = die2 = 0
    cs = 0
    cturn_total = 0
    while cturn_total < 20 and die1 != 1 and die2 != 1:
          # gnerate two roll dice
                die1 =random.randint(1,6)
                die2 =random.randint(1,6)
                ctotal = die1 + die2 
                
                 
                if die1 != 1 and die2 != 1:
                     print ("Die1 is: ",die1,"Die2 is: ",die2,"Die total is:", ptotal)
                     cturn_total +=  ctotal # update player score
                     print ("Turn total:",cturn_total , "Potential score:",cs + cturn_total)
                     
                     
                elif die1== 1 and die2 == 1:
                     print ("Die1 is: ",die1,"Die2 is: ",die2,"Die total is:", ptotal)
                     print("*** Ouch! That hurts!- Two ONEs - computer loses it  ")
                     print("player score:",pturn_total,"computer score:",cturn_total)

                elif die1== 1 or die2 == 1:
                     print ("Die1 is: ",die1,"Die2 is: ",die2,"Die total is:", ctotal)
                     print(" *** You rolled a ONE turn over - no point for computer! ")
                     print("player score:",pturn_total,"computer score:",cturn_total)
                     
                else:     

                     potential_score >= 100
                     print("computer win! sorry!", player_name)
                     
                     
    #when cturn_total >= 20
    if cturn_total >= 20:
        print("\n|*** Hold!\n| ")
        print("player score:",pturn_total,"computer score:",cturn_total)
                     
          
    print("-----------------------------------------END copmuter turn----------------------------------")

# print game outcome
print ("|*********************** GAME OVER ***************************")
###################################################################################
# while loop to play again
msg, choice ="Would you like play again?","g"
while choice !='y' and choice!='n':
      choice = input(msg)
      if choice == 'y':  
          print("That was fun!")
          print("lets start the game again")

      else:
          print("Thank for playing")
          choice = input(msg)
