## d4 Fixed Board Dice Game

import math
import random
import numpy as np

## define variables

outcomes = 4
roll = 0

twoEightWin = 0  ## Variables for counting game wins
threeSevenWin = 0
fourSixWin = 0
fiveWin = 0


trials = int(input("Number of Trials: "))         ## Number of Trials

k = 0

for k in range(0, trials):

    twoEight = 0
    threeSeven = 0
    fourSix = 0
    five = 0

    end = 0

    while (end == 0):  ##  Optional output commands are marked as comment lines

        roll = (random.randint(1, 4) + random.randint(1, 4))
        ## print('Roll ', k, ' = ', roll)
        if (roll == 2) or (roll == 8):
            twoEight = twoEight + 1
        elif (roll == 3) or (roll == 7):
            threeSeven = threeSeven + 1
        elif (roll == 4) or (roll == 6):
            fourSix = fourSix + 1
        else:
            five = five + 1

        if (twoEight == 6):
            twoEightWin = twoEightWin + 1
            ## print('Trial #', k, ', Two/Twelve wins.')
            end = 1
        elif (threeSeven == 6):
            threeSevenWin = threeSevenWin + 1
            ## print('Trial #', k, ', Three/Eleven wins.')
            end = 1
        elif (fourSix == 6):
            fourSixWin = fourSixWin + 1
            ## print('Trial #', k, ', Four/Ten wins.')
            end = 1
        elif (five == 6):
            fiveWin = fiveWin + 1
            ## print('Trial #', k, ', Seven wins.')
            end = 1


print('Fixed Board, d4 and ',trials,' trials:')
print(' # # # # # # # ')
print('Two/Eight won ', twoEightWin, 'times for ', (100 * twoEightWin) / trials, '%.')
print('Three/Seven won ', threeSevenWin, 'times for ', (100 * threeSevenWin) / trials, '%.')
print('Four/Six won ', fourSixWin, 'times for ', (100 * fourSixWin) / trials, '%.')
print('Five won ', fiveWin, 'times for ', (100 * fiveWin) / trials, '%.')

fairShare = trials/4
print(fairShare)
variance = ((((twoEightWin-fairShare)**2)+((threeSevenWin-fairShare)**2)+((fourSixWin-fairShare)**2)+((fiveWin-fairShare)**2))/(trials-1))
print('Game variance is', variance)


