forked from InnesWarwick/TeamBBB-RPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (63 loc) · 1.76 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import random
from enum import Enum
import time
class RPS(Enum):
ROCK = 0
PAPER = 1
SCISSORS = 2
#main method
def main():
print("enter your action then the bot will respond")
playerMove = getInput()
botMove = botsMove()
def validInput(input):
return{ #0, 1, 2
"rock": RPS.ROCK,
"paper": RPS.PAPER,
"scissors": RPS.SCISSORS
}.get(input, "invalid")
# this gets user input
def getInput():
# user input
print("ROCK (R) | PAPER (P) | SCISSORS (S)")
#Getting valid Input for the user
userInput = input("Enter your input here").lower()
if validInput(userInput) == "invalid":
print("shit.")
if userInput != "ROCK" or userInput != "PAPER" or userInput != "SCISSORS":
print("please enter a valid input")
else:
return userInput
def botsMove():
botChoice = random.randint(1, 3)
match botChoice:
case 1:
botChoice = "ROCK"
case 2:
botChoice = "PAPER"
case 3:
botChoice = "SCISSORS"
return botChoice
def compareMoves(playerMove, botMove):
winner = ""
# rock > scissors
# scissors > paper
# paper > rock
if playerMove == "ROCK" and botMove != "PAPER":
winner = "Player wins"
elif playerMove == "PAPER" and botMove != "SCISSORS":
winner = "Player wins"
elif playerMove == "SCISSORS" and botMove != "ROCK":
winner = "Player wins"
elif playerMove == botMove:
winner = "A draw"
else:
winner = "Bot wins"
print("3...")
time.sleep(1)
print("2..")
time.sleep(1)
print("1..")
print(f"bot chose {botMove} you chose {playerMove} the result is {winner}")
if __name__ == "__main__":
main()