# See http://cs.gettysburg.edu/~tneller/resources/pig/cs1/ for I/O specification.
from array import *
from random import *

GOAL = 100
HOLD_AT = 20
MAX_ROLL = 6

def exercise1():
    '''1. Simulate a single turn of a computer Pig player that holds when the turn
   total reaches 20. Output each die roll and the final score gain for the
   computer player on separate lines.'''
    

def exercise2():
    '''2. What are the probable outcomes of the "hold at 20" policy? Run this
     simulation 1,000,000 times (without dice roll and final score output),
     counting occurrences of the possible score gains in an array. Output each
     possible gain on a separate line along with the estimated probability of
     achieving it when holding at 20.'''


def exercise3():    
    '''3. It does not make sense to continue rolling when holding would win the
     game. Modify your simulation so that the computer player is given a non-
     negative score < 100 from standard input, and holds when the turn total
     reaches 20 or the goal score of 100 would be achieved. Output each dice
     roll, the final score gain, and the score at the end of each turn for the
     computer player on separate lines.'''


def exercise4():
    '''4. Using a variable score initialized to 0, simulate a game played to 100
     points by a computer player with this policy.'''


def exercise5():
    '''5. How many turns on average does it take for the "hold at 20" player to
     reach 100? Run this simulation 1,000,000 times (without previous output),
     and output the average number of turns the computer takes to reach the goal
     score.'''


def exercise6():
    '''6. Modify the previous game simulation so that two computer players are
     competing with the same policy. At the beginning of each turn, output both
     scores and which player is currently playing, along with previous roll and
     score output.'''


def exercise7(): 
    '''7. There is an advantage to going first in Pig, but how big an advantage
     is it for "hold at 20" play? Run this simulation 1,000,000 times (without
     previous output), and output the fraction of games won by the first player.'''


def exercise8(): 
    '''8. Modify your two-computer simulation so that one of the players is
     randomly chosen to be the user. Prompt the user for decision from standard
     input, with an empty string (return/enter) indicating a decision to roll,
     and any other input line indicating a decision to hold.'''


def exercise2b():
    '''2b. What are the probable outcomes of the "hold at 20" policy? Compute
     using a dynamic programming approach as shown at:
     http://cs.gettysburg.edu/~tneller/resources/pig/cs1/turnOutcomes.html.
     Output each possible gain on a separate line along with the estimated
     probability of achieving it when holding at 20.'''

