Created
November 8, 2015 05:54
-
-
Save arkag/2c8ca27034f14534c380 to your computer and use it in GitHub Desktop.
Logic for Rock Paper Scissors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| weapons = ["Rock", "Paper", "Scissors", "rock", "paper", "scissors"] | |
| players = ["computer", "Computer", "human", "Human"] | |
| rock = ["Rock", "rock"] | |
| paper = ["Paper", "paper"] | |
| scissors = ["Scissors", "scissors"] | |
| res = "" | |
| p1 = "" | |
| p2 = "" | |
| def game(): | |
| print("Welcome to Rock Paper Scissors!") | |
| game = input("Would you like to play with a human or a computer?\n") | |
| while True: | |
| if(game not in players): | |
| game = input("Please pick a better opponent!\n") | |
| else: | |
| break | |
| while True: | |
| if(game == "human"): | |
| human() | |
| if("n" in res): | |
| break | |
| else: | |
| continue | |
| elif(game == "computer"): | |
| pc() | |
| if("n" in res): | |
| break | |
| else: | |
| continue | |
| def human(): | |
| p1 = str(input("Player 1 - Please choose a weapon!\n")) | |
| while True: | |
| if(p1 not in weapons): | |
| p1 = input("Please choose a better weapon!\n") | |
| else: | |
| print("You chose: " + str(p1)) | |
| break | |
| p2 = str(input("Player 2 - Please choose a weapon!\n")) | |
| while True: | |
| if(p2 not in weapons): | |
| p2 = input("Please choose a better weapon!\n") | |
| else: | |
| print("You chose: " + str(p2)) | |
| break | |
| rpslogic() | |
| retry() | |
| def pc(): | |
| while True: | |
| p1 = input("Please choose a weapon!\n") | |
| if(p1 not in weapons): | |
| p1 = input("Please choose a better weapon!\n") | |
| break | |
| def rpslogic(): | |
| # debugging | |
| # print(p1 in rock) | |
| # print(p2 in scissors) | |
| if(p1 == p2): | |
| print("It's a tie!") | |
| elif(p1 in rock and p2 in paper): | |
| print("Player 2 wins!") | |
| elif(p1 in paper and p2 in rock): | |
| print("Player 1 wins!") | |
| elif(p1 in scissors and p2 in paper): | |
| print("Player 1 wins!") | |
| elif(p1 in scissors and p2 in rock): | |
| print("Player 2 wins!") | |
| elif(p1 in rock and p2 in scissors): | |
| print("Player 1 wins!") | |
| else: | |
| print("Player 2 wins!") | |
| def retry(): | |
| while True: | |
| res = input("Would you like to play again?\n") | |
| if("n" in res or "y" in res): | |
| break | |
| else: | |
| while("n" not in res or "y" not in res): | |
| res = input("Please pick a better response.\n") | |
| game() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment