## David Ryan Mckinney
## SDEV140
## Rock Paper Scissors Lizard Spock
## M03_Assn1_Ex21 extra credit
## 1/29/21
## Program written to play rock paper scissors lizard spock vs an AI opponent

## Rules as I understand them:
## Scissors cuts paper
## Paper covers rock
## Rock smashes scissors
## Lizard poisons Spock
## Spock smashes scissors
## Scissors cuts lizard
## Lizard eats paper
## Paper disproves Spock
## Spock vaporizes rock
## Rock squishes lizard


# importing random module for using random.randrange
import random

# function to convert number to name
def number_to_name(number):
    if number == 0:
        return "rock"
    elif number == 1:
        return "Spock"
    elif number == 2:
        return "paper"
    elif number == 3:
        return "lizard"
    elif number == 4:
        return "scissors"
    else:
        return "Error"

# function to convert name to number
def name_to_number(name):
    if name == "rock":
        return 0
    elif name == "Spock":
        return 1
    elif name == "paper":
        return 2
    elif name == "lizard":
        return 3
    elif name == "scissors":
        return 4
    else:
        print (name + "is not a character in RPSLS")


# function which selects the winner
def main(guess): 
    
    # convert name to player_number using name_to_number
    player_number = name_to_number(guess)
    
    # assign random guess for comp_number using random.randrange()
    comp_number = random.randrange(0,5)

    # calculate difference of player_number and comp_number
    winner = (comp_number - player_number) % 5

    # use if/else to determine winner
    if winner < 3:
        player_win = False
    else:
        player_win = True
    
    # convert comp_number to name using number_to_name function
    comp_name = number_to_name(comp_number)
    
    # print results
    print ("Player chooses " + guess)
    print ("Computer chooses " + comp_name)
    if player_win:
        print ("Player wins!\n")
    elif comp_number == player_number:
        print ("Player and computer tie!\n")
    else:
        print ("Computer wins!\n")

    
player_guess = input('Enter your choice.. Options: rock, Spock, paper, lizard, scissors\n')


main(str(player_guess))