# Arup Guha
# 7/6/2012
# Simulates how many turns it takes to go around a Monopoly board
# (without special squares...)
import random

def main():

    # Initialize necessary variables.
    i = 0
    NUMTRIALS = 100000
    sumturns = 0

    # Run each trial
    while i < NUMTRIALS:

        # Set up one trip around the board.
        spot = 0
        turns = 0

        # Stop when we get around the board.
        while spot < 40:

            # Start this turn.
            turns = turns + 1

            # See if the spot we actually land on is the jail spot.
            inJail = False

            # Make sure we don't go more than three times.
            doublecnt = 0
            while doublecnt < 3:

                # Do this roll and update.
                roll1 = random.randint(1,6)
                roll2 = random.randint(1,6)
                roll = roll1 + roll2
                spot = spot + roll

                # Oops, we did something bad!
                if spot == 30:
                    inJail = True
                    break;

                # Get out if we didn't get doubles.
                if roll1 != roll2:
                    break
                
                doublecnt = doublecnt + 1

            # Oops time to go to jail - we must stay in three turns.
            if doublecnt == 3 or inJail:
                spot = 10
                turns += 3
            
        # Update number of total turns.    
        sumturns = sumturns + turns
        i = i+1

    # Print out our final average.
    average = sumturns/NUMTRIALS
    print("Average is",average)

main()
