- if state is None:
- state = self.generate_state(health, wins)
- self.update_state(state)
+ @classmethod
+ def new_game(cls, max_health, wins_required, locations_definition):
+ state = {
+ 'max_health': max_health,
+ 'health': max_health,
+ 'wins_required': wins_required,
+ 'wins': 0,
+ 'locations': locations_definition,
+ }
+ player = Player(0x0f, (2, 2))
+ board_locations = cls.generate_board(locations_definition)
+ return cls(state, player, board_locations)
+
+ @classmethod
+ def import_game(cls, definition):
+ state = definition.copy()
+ player = Player.import_player(state.pop('player'))
+ board_locations = cls.import_board_locations(
+ state.pop('board_locations'))
+ return cls(state, player, board_locations)