lundi 28 septembre 2015

Rock, Paper, Scissor, Spock, Lizard in python, Player 2 automatically wins

for an exercise we need to recreate the game played by the members of the bigbang theory: Rock, Paper, Scissor, Spock, Lizard. I managed to recreate it almost completely, the only problem is: Player 2 automatically wins. Can someone tell me where I need to change the code and also explain why?

import sys

t = len(sys.argv)

if(t < 2 or t > 3):
    print("Usage: rpsls.py symbool1 symbool2")
    exit()
i = 1
while (i > 0):
    a = sys.argv[1]
    b = sys.argv[2]
    a = a.lower()
    b = b.lower()
    if(a != "rock" and a != "paper" and a != "scissor" and a != "lizard" and a != "spock"):
        print("What's that? please use a real symbol!")

    elif(b != "rock" and b != "paper" and b != "scissor" and b != "lizard" and b != "spock"):
        print("What's that? please use a real symbol!")

    else:
        if (a == "paper" and b == "scissor"):
            s = True
            i = 0
        else:
            s = False
            i = 0
        if(a == "paper" and b == "rock"):
            s = True
            i = 0
        else:
            s = False
            i = 0
        if(a == "rock" and b == "lizard"):
            s = True
            i = 0
        else:
            s = False
            i = 0
        if(a == "lizard" and b == "spock"):
            s = True
            i = 0
        else:
            s = False
            i = 0
        if(a == "spock" and b == "scissors"):
            s = True
            i = 0
        else:
            s = False
            i = 0
        if(a == "scissor" and b == "lizard"):
            s = True
            i = 0
        else:
            s = False
            i = 0
        if(a == "lizard" and b == "paper"):
            s = True
            i = 0
        else:
            s = False
            i = 0
        if(a == "paper" and b == "spock"):
            s = True
            i = 0
        else:
            s = False
            i = 0
        if(a == "spock" and b == "rock"):
            s = True
            i = 0
        else:
            s = False
            i = 0
        if(a == "rock" and b == "scissor"):
            s = True
            i = 0
        else:
            s = False
            i = 0
        if(a == b):
            print("It's a tie!")
            i = 0
            exit()

if(s == True):
        print("Player 1 wins!")
if(s == False):
        print("Player 2 wins!")

Aucun commentaire:

Enregistrer un commentaire