# Arup Guha
# 10/15/2020
# Casino Program

import random

# Returns the value of a single standard die roll.
def rollOneDie():
    return random.randint(1,6)

# Returns the sum of n standard dice rolls.
def rollDice(n):
    total = 0
    for i in range(n):
        total += random.randint(1,6)
    return total

# Plays a game of craps and returns True if the user won, False otherwise.
def craps():

    # Do the first roll.
    firstRoll = rollDice(2)
    print("Your first roll is", firstRoll)

    # In craps, we win with a 7 or 11...and you get a slurpee!
    if firstRoll == 7 or firstRoll == 11:
        print("Congrats, you win!")
        return True

    # In craps, 2,3, and 12 are losing first rolls.
    if firstRoll == 2 or firstRoll == 3 or firstRoll == 12:
        print("Sorry, you lose!")
        return False

    # Game continues.
    print("The game will continue. Your point is", firstRoll)
    print("If you can roll that again before getting 7, you win!")

    # Roll again, show user what they got.
    nextRoll = rollDice(2)
    print("This time around you rolled", nextRoll)

    # Keep on going until you get 7 or the point.
    while nextRoll != 7 and nextRoll != firstRoll:
        print("The game will continue as that is not an ending roll.")
        nextRoll = rollDice(2)
        print("This time around you rolled", nextRoll)

    # In this case the user loses.
    if nextRoll == 7:
        print("Sorry you lose, you rolled 7 first.")
        return False

    # User wins
    else:
        print("Great, you win! You rolled",firstRoll,"again before 7.")
        return True

def arupsdice():

    # Do the first roll.
    firstRoll = rollDice(2)
    print("Your first roll is", firstRoll)

    # 1 roll win.
    if firstRoll == 11 or firstRoll == 12:
        print("Congrats you win!")
        return True

    # 1 roll loss.
    if firstRoll == 2:
        print("Sorry, this means you lose.")
        return False

    # Get a second roll.
    secondRoll = rollDice(2)
    print("You got", secondRoll,"for your second roll.")

    # Winning case.
    if secondRoll > firstRoll:
        print("You beat your first roll so you win!")
        return True

    # If we get here, we lose.
    print("Sorry, you didn't beat your first roll, so you lose.")
    return False

# Returns the user's menu choice, no error checking done.
def menu():

    # Print the menu.
    print("Welcome to our casino. What would you like to do?")
    print("1. Play Arup's Game of Dice.")
    print("2. Play Craps.")
    print("3. Quit.")

    # Get answer and return it.
    ans = int(input(""))
    return ans

#
def main():

    # Get how much money the user is bringing to the casino.
    money = int(input("How much money do you have?\n"))
    savemoney = money

    # Get the user's choice.
    ans = menu()

    # Keep playing!
    while money > 0 and ans != 3:

        # Get wager.
        wager = int(input("How much is your wager?\n"))

        # Do the appropriate game.
        result = -1
        if ans == 1:
            result = arupsdice()
        elif ans == 2:
            result = craps()
        else:
            print("That was not a valid menu option.")

        # Only update money if a game was played.
        if ans == 1 or ans == 2:

            # Update money.
            if result:
                money += wager
            else:
                money -= wager

        # Update user about their money and see if they want to play again.
        print("Now you have", money,"left after playing.")
        ans = menu()

    # Ending message.
    print("Thanks for playing, you now have", money,"dollars.")

    # Print their relative status.
    if money > savemoney:
        print("Great job, you earned", money-savemoney," dollars.")
    elif savemoney == money:
        print("You are lucky you did not lose any money!")
    else:
        print("You lost",savemoney-money, "dollars.")

# Run it.
main()

'''
My test of my game
def testarupsgame():
    for i in range(10):
        arupsdice()
        print("-------------------")

testarupsgame()
'''

'''
My test of rollDice
def testRollDice():
    for i in range(50):
        print(rollDice(2))

testRollDice()
'''


