-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
58 lines (45 loc) · 1.36 KB
/
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
import typing
class Game:
def __init__(self, id):
self.p1Went: bool = False
self.p2Went: bool = False
self.ready: bool = False
self.id = id
self.moves: typing.Tuple[typing.Optional[str], typing.Optional[str]] = [
None,
None,
]
self.wins: typing.Tuple[int, int] = [0, 0]
self.ties: int = 0
def get_player_move(self, p) -> typing.Optional[str]:
return self.moves[p]
def play(self, player: int, move: str) -> None:
self.moves[player] = move
if player == 0:
self.p1Went = True
else:
self.p2Went = True
def isConnected(self) -> bool:
return self.ready
def bothWent(self) -> bool:
return self.p1Went and self.p2Went
def winner(self):
p1 = self.moves[0].upper()[0]
p2 = self.moves[1].upper()[0]
winner = -1
if p1 == "R" and p2 == "P":
winner = 1
elif p1 == "R" and p2 == "S":
winner = 0
elif p1 == "S" and p2 == "R":
winner = 1
elif p1 == "S" and p2 == "P":
winner = 0
elif p1 == "P" and p2 == "R":
winner = 0
elif p1 == "P" and p2 == "S":
winner = 1
return winner
def resetWent(self) -> None:
self.p1Went = False
self.p2Went = False