-
Notifications
You must be signed in to change notification settings - Fork 0
/
RPSLS Game.py
123 lines (83 loc) · 2.85 KB
/
RPSLS Game.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"""
This is a Python script that is used to create the RPSLS i.e.
Rock-Paper-Scissors-Lizard-Spock game.
This is my first project.
In this game, the user plays against the computer and provides an
input from the options available to them. The exact rules are a follows: -
The method for determining the winner is to assign each of the five choices a number:
0 — rock
1 — Spock
2 — paper
3 — lizard
4 — scissors
In this expanded list, each choice wins against the preceding two choices and loses against the following two choices
(if rock and scissors are thought of as being adjacent using modular arithmetic).
"""
import random # importing required libraries.
# Function to create codes.
def name_to_code(user_inp):
if user_inp == "rock" or user_inp == "ROCK" :
user_code = 0
elif user_inp == "spock" or user_inp == "SPOCK" :
user_code = 1
elif user_inp == "paper" or user_inp == "PAPER" :
user_code = 2
elif user_inp == "LIZARD" or user_inp == "lizard" :
user_code = 3
elif user_inp == "scissors" or user_inp == "SCISSORS" :
user_code = 4
else :
print("Choose a correct choice please!!!!!!")
return user_code
# Function to display the choice from the code.
def code_to_name(code):
if code == 0 :
inp = "ROCK"
elif code == 1:
inp = "SPOCK"
elif code == 2:
inp = "PAPER"
elif code == 3:
inp = "LIZARD"
elif code == 4:
inp = "SCISSORS"
else :
PASS
return inp
# Main game's logic
def rspls(ref,comp) :
error = 2 - ref # User input referenced to 2
comp = (comp+error) % 5
if(comp - 2 > 0) :
print(" Sorry , you loose this round ")
elif(comp - 2 <0) :
print("YAY, you win")
else :
print("Its a tie")
# Main game's code.
print(" Welcome to vaishvi's GAMING world!!!!!!!!!!!!!!!")
print("========================================================================================")
print("")
print("We are playing RPSLS. Please choose your choice from the following:")
print("1) Rock")
print("2) Spock")
print("3) Paper")
print("4) Lizard")
print("5) Scissors")
print("Please choose an option now : ")
user_inp = input("Your Input please") # Taking user input.
comp_code = random.randint(0,4) # Taking random input for computer.
comp_inp = code_to_name(comp_code)
user_code = name_to_code(user_inp)
print("")
print("")
if user_code == "NONE" :
print("BTW, computer choose :" , comp_inp)
else :
print("Your choice was : " , user_inp)
print("Computer's choice was : ", comp_inp)
print("And the result is :")
rspls(user_code,comp_code)
print("")
print("")
print("Game Ends here!!!!!!!!")