Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored user input handling to use .lower() function for case insensitivity #197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 56 additions & 49 deletions Rock Paper Scissors Game/main.py
Original file line number Diff line number Diff line change
@@ -1,87 +1,94 @@
#Rock Paper Scissors game by marsian
print("\n\n\nRock Paper Scissors by marsian83\n\npresss Ctrl+. when you feel like exitting the game.")
# Rock Paper Scissors game by marsian
print("\n\n\nRock Paper Scissors by marsian83\n\npress Ctrl+. when you feel like exitting the game.")
input("\n\n<<PRESS ENTER TO BEGIN>>\n")
print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n")

#Framework declaration
# Framework declaration
from time import sleep
from random import choice


def game():
print("\n\n\n\n\n\n\n\nDecide your move, enter \"R\" for Rock, \"S\" for Scissors and \"P\"for Paper")
tempVal=input()
while tempVal != 'R' and tempVal != 'S' and tempVal != 'P' and tempVal != 'r' and tempVal != 's' and tempVal != 'p':
tempVal = input().lower()
while tempVal not in ['r', 's', 'p']:
print("Decide your move, enter \"R\" for Rock, \"S\" for Scissors and \"P\"for Paper")
tempVal=input();
tempVal = input().lower()
sleep(0.13)
if tempVal == "R" or tempVal == "r":
Pmove=1
elif tempVal == "P" or tempVal == "p":
Pmove=2
elif tempVal == "S" or tempVal == "s":
Pmove=3
if tempVal == "r":
Pmove = 1
elif tempVal == "p":
Pmove = 2
elif tempVal == "s":
Pmove = 3
else:
print("Custom_ERROR-01 : can't recognize user's input")
raise SystemExit(0);
raise SystemExit(0)
sleep(0.13)
Cmove=choice(MoveSet)
Cmove = choice(MoveSet)
if Cmove == 1:
cpumove='Rock'
cpumove = 'Rock'
elif Cmove == 2:
cpumove='Paper'
cpumove = 'Paper'
elif Cmove == 3:
cpumove='Scissor'
cpumove = 'Scissor'
else:
print("Custom_ERROR-00 : CPU's move unrecognizable")
raise SystemExit(0)
del tempVal;
sleep(0.038)
return Cmove, Pmove, cpumove
def decisive(Cmove,Pmove):
if [Cmove,Pmove] == [1,3] or [Cmove,Pmove] == [2,1] or [Cmove,Pmove] == [3,2]:
winner=1
elif [Cmove,Pmove] == [1,2] or [Cmove,Pmove] == [2,3] or [Cmove,Pmove] == [3,1]:
winner=2
elif [Cmove,Pmove] == [1,1] or [Cmove,Pmove] == [2,2] or [Cmove,Pmove] == [3,3]:
winner=0


def decisive(Cmove, Pmove):
if [Cmove, Pmove] in [[1, 3], [2, 1], [3, 2]]:
winner = 1
elif [Cmove, Pmove] in [[1, 2], [2, 3], [3, 1]]:
winner = 2
elif [Cmove, Pmove] in [[1, 1], [2, 2], [3, 3]]:
winner = 0
else:
print("Custom_ERROR-03 : Set [cpumove,playermove] was assigned an unexpected value")
raise SystemExit(0)
return winner
def Scoreboard(winner,cm,cs,ps):


def Scoreboard(winner, cm, cs, ps):
if winner == 1:
print("\nCPU won the round by choosing",cm)
cs=cs+1
print("\nCPU won the round by choosing", cm)
cs = cs + 1
elif winner == 2:
print("\nPlayer won the round!")
ps=ps+1
ps = ps + 1
else:
print("Custom_ERROR-02 : Scoreboard function recieved explicit values")
raise SystemExit(0)
print("\nSession Score:")
print("Player : ",ps)
print("CPU : ",cs)
print("Player : ", ps)
print("CPU : ", cs)
return cs, ps

#Variable declaration
MoveSet = [1,2,3]
Cmove=0
Pmove=0
Cscore=0
Pscore=0

#Driver Code
# Variable declaration
MoveSet = [1, 2, 3]
Cmove = 0
Pmove = 0
Cscore = 0
Pscore = 0

# Driver Code
while True:
Cmove,Pmove,cpumove=game()
winner=decisive(Cmove,Pmove)
Cmove, Pmove, cpumove = game()
winner = decisive(Cmove, Pmove)
while winner == 0:
print("WoW! A Draw!\nBoth Player and CPU have chosen",cpumove)
print("WoW! A Draw!\nBoth Player and CPU have chosen", cpumove)
print("let's go again")
Cmove,Pmove,cpumove=game()
winner=decisive(Cmove,Pmove)
Cmove, Pmove, cpumove = game()
winner = decisive(Cmove, Pmove)
sleep(0.13)
cmCache=cpumove;
print("CPU - ",cmCache)
RoundWinner=winner
cs,ps=Scoreboard(RoundWinner,cmCache,Cscore,Pscore)
Cscore=cs; Pscore=ps
input("<<< PRESS ENTER TO CONTINUE >>>");
cmCache = cpumove
print("CPU - ", cmCache)
RoundWinner = winner
cs, ps = Scoreboard(RoundWinner, cmCache, Cscore, Pscore)
Cscore = cs
Pscore = ps
input("<<< PRESS ENTER TO CONTINUE >>>")