-
Notifications
You must be signed in to change notification settings - Fork 1
/
game_controller.py
65 lines (54 loc) · 1.65 KB
/
game_controller.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
from log import logger
import copy
class GameNotFinishedException(Exception):
pass
class GameController:
'''
GameController is a class, which controls game manager.
Usage:
>> game_controller = GameController(config, players, signature, jury_state)
Examples:
# Saving jury states to array
>> game_controller.report_state(jury_state)
# Getting players
>> list_of_players = game_controller.get_players()
# Getting scores
>> dict_of_scores = game_controller.get_scores()
'''
def __init__(self, players, signature, jury_state, _simulator):
'''
Constructor of class. Creating jury states array,
initializing base variables
'''
self._players = players
self.signature = signature
self.jury_states = [jury_state]
self.is_finished = False
self.simulator = _simulator
def __getstate__(self):
state = copy.copy(self.__dict__)
del state['simulator']
return state
def __setstate__(self, d):
self.__dict__ = d
def __getattr__(self, key):
return eval('self.simulator.' + key)
def finish_game(self, scores):
'''
Finishes game with `scores`
'''
self.is_finished = True
self._scores = scores
print()
logger.info('game finished')
def get_scores(self):
'''
Gets scores of finished game
'''
if not self.is_finished:
raise GameNotFinishedException()
return self._scores
def __lt__(self, other):
return self.signature < other.signature
def get_players(self):
return self._players