# Arup Guha
# 4/3/2023, 4/4/2023
# Allows play of "How Low Can You Go?" for Intro Probability COT 3100

import random

# Shuffles the list items and returns it.
def shuffle(items):
    for i in range(20*len(items)):
        x = random.randint(0,len(items)-1)
        y = random.randint(0,len(items)-1)
        tmp = items[x]
        items[x] = items[y]
        items[y] = tmp
    return items

# Returns a random combination of k integers from the list 1,2,3...,n.
def getRndCombo(n,k):

    # Keep track of what is chosen.
    chosen = []
    for i in range(n):
        chosen.append(False)
    got = 0

    # Keep picking until we have enough items.
    while got < k:
        x = random.randint(0,n-1)
        if not chosen[x]:
            got += 1
            chosen[x] = True

    # Add chosen items to a list to return.
    items = []
    for i in range(n):
        if chosen[i]:
            items.append(i+1)
    return shuffle(items)

# Wrote this to make sure the distribution of combinations is okay.
def checkOkay():

    # Will keep track of # of times each ordering is found.
    freq = []
    for i in range(6):
        freq.append(0)

    # Try 100000 times.
    for i in range(100000):
        tmp = getRndCombo(10,3)

        # Add one to appropriate bin.
        if tmp[0] < tmp[1] and tmp[1] < tmp[2]:
            freq[0]+=1
        elif tmp[0] < tmp[2] and tmp[2] < tmp[1]:
            freq[1]+=1
        elif tmp[1] < tmp[0] and tmp[0] < tmp[2]:
            freq[2]+=1
        elif tmp[1] < tmp[2] and tmp[2] < tmp[0]:
            freq[3]+=1
        elif tmp[2] < tmp[0] and tmp[0] < tmp[1]:
            freq[4]+=1
        else:
            freq[5]+=1

    # I will visually inspect.
    for i in range(6):
        print(freq[i],end=" ")
    print()

# Plays one round of the game.
def playGame():

    # Get the random setting of values.
    realList = getRndCombo(10,3)

    # Get user's choice.
    print("What would you like to choose?\nA B C")
    letter = input().strip()

    # Reveal selection.
    print("Now, you can see the number under the letter.")
    for i in range(3):
        if i == ord(letter[0])-ord('A'):
            print(realList[i], end= " ")
        else:
            print(chr(i+ord('A')), end=" ")

    # Ask which door they want now.
    print("You can either stay with",letter,"or change.")
    print("Which letter do you want?")
    letter = input().strip()
    idx = ord(letter[0])-ord('A')

    # They win if their door has the smallest number.
    win = True
    for i in range(3):
        if realList[idx] > realList[i]:
            win = False

    # Print outcome.
    if win:
        print("You win!")
    else:
        print("You lose!")

    # Show all values.
    print("Here are all three numbers.")
    for i in range(3):
        print(realList[i], end= " ")
    print()

# Run it!
playGame()
