# A modified version of Rock-paper-scissors-lizard-Spock developed as part of project for coursera course
#on interactive programming in python (from Rice university)
# This program will get the player's input( 5 input cases), generate the computer's random input, and will decide the winner
# The key idea of this program is to equate the strings
# "rock", "paper", "scissors", "lizard", "Spock" to numbers
# as follows:
# 0 - rock
# 1 - Spock
# 2 - paper
# 3 - lizard
# 4 - scissors

# helper functions

def name_to_number(name):
"""
This function returns a number corresponding to the name 
passed in accordance with the list at the start of this program
"""
    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 "Invalid name"

def number_to_name(number):
"""
This function returns a name corresponding to the number 
passed in accordance with the list at the start of this program
"""
    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:
        print "Invalid number"
    
def rpsls(player_choice):
"""
Function for the actual game
This function will get the player's input, generate the
computer's random input, and will decide the winner.
"""
    # print a blank line to separate consecutive games
    print "\n "
    # print out the message for the player's choice
    print "Player chooses "+ player_choice
    # convert the player's choice to player_number using the function name_to_number()
    player_number=name_to_number(player_choice)
    # compute random guess for comp_number using random.randrange()
    import random
    comp_number=random.randrange(0,5)
    # convert comp_number to comp_choice using the function number_to_name()
    comp_choice=number_to_name(comp_number)
    # print out the message for computer's choice
    print "Computer chooses "+comp_choice
    # compute difference of comp_number and player_number modulo five
    difference= (comp_number-player_number)%5
    # use if/elif/else to determine winner, print winner message
    if(difference == 0):
        print "Player and Computer tie!"
    elif (difference==1) or (difference==2):
        print "Computer wins!"
    elif (difference==3) or (difference==4):
        print "Player wins!"
    else:
        print "Game not played well! Error in computer or player input!"

#Test with every player choice        
rpsls("rock")
rpsls("Spock")
rpsls("paper")
rpsls("lizard")
rpsls("scissors")



