-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsps.py
80 lines (69 loc) · 2.13 KB
/
sps.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
import logging
import logging.config
import random
logging.config.fileConfig("logging.conf")
logger = logging.getLogger("simpleExample")
class ScissorsPaperStone:
r"""
Initialise all actions that can be performed
"""
actions = ["Scissor", "Paper", "Stone"]
def __init__(self, uid, choice) -> None:
r"""
Records the unique id for statistical review
Choice to determine who wins
"""
self.uid = uid
self.choice = choice
self.program_choice = -1
def generate_number(self) -> int:
r"""
Generate a number within 3 by using 6 pairs of digit
"""
number_list = []
while len(number_list) < 6:
num = random.randint(1, 49)
if num not in number_list:
number_list.append(num)
number_list.sort()
self.program_choice = number_list
def play(self) -> str:
r"""
Plays a game with the bot
"""
self.generate_number()
outcome = ScissorsPaperStone.actions[sum(self.program_choice) % 3]
logger.debug(
"--- Scissors Paper Stone: Program has chosen %s with numbers %s",
outcome,
self.program_choice,
)
return self.determine_result(outcome)
def determine_result(self, outcome) -> str:
r"""
Determines the result of the game if it is a Win, Loss, or Draw.
"""
if self.choice == "Stone":
if outcome == "Scissor":
return "Win"
if outcome == "Paper":
return "Lose"
elif self.choice == "Scissor":
if outcome == "Paper":
return "Win"
if outcome == "Stone":
return "Lose"
elif self.choice == "Paper":
if outcome == "Stone":
return "Win"
if outcome == "Scissor":
return "Lose"
return "Draw"
def usage() -> None:
r"""
How to initialise, play, and get result of play
"""
game = ScissorsPaperStone("test-uid", "Stone")
print(game.play())
if __name__ == "__main__":
usage()