-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_utils.py
More file actions
47 lines (35 loc) · 1.15 KB
/
game_utils.py
File metadata and controls
47 lines (35 loc) · 1.15 KB
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
from constants import stronger_gesture, computer_gestures
from cv2 import imread
import random
class Gesture:
gesture_names = ("rock", "paper", "scissors")
def __init__(self, name):
self.name = name
self.player = 0
@staticmethod
def generate_random():
generated_gesture = Gesture(random.choice(Gesture.gesture_names))
generated_gesture.player = 1
return generated_gesture
def __repr__(self):
return f"Gesture({self.name})"
def __eq__(self, other):
return self.name == other.name
def __gt__(self, other):
return stronger_gesture[other.name] == self.name
def __lt__(self, other):
return stronger_gesture[other.name] != self.name
class RockPaperScissors:
ids = {
0: "person",
1: "computer",
2: "draw"
}
@classmethod
def get_result(cls, person_gesture, computer_gesture):
arg_list = [person_gesture, computer_gesture]
if not person_gesture == computer_gesture:
winner = arg_list.index(max(arg_list))
return winner, f"{cls.ids[winner]} wins"
else:
return 2, "draw"