def stop(self): if self._running: self._running = False try: game_phase, state, image = self._read_and_process_server_response( ) assert game_phase == GamePhase.ACT_STATE, "Expecting ACT_STATE from GVGAI, but received %s" % GamePhase( game_phase) self._abort_game() self._choose_level("END") except AssertionError as e: self._logger.error(e) try: if hasattr(self, 'java'): self.java.kill() self._logpipe.close() except AssertionError as e: self._logger.error(e)
def _end_game(self): game_phase, state, image = self._read_and_process_server_response() assert game_phase == GamePhase.END_STATE, "Expecting END_STATE from GVGAI, but received %s" % GamePhase( game_phase) self.io.writeToServer(AgentPhase.END_STATE)
def _observe(self): agent_phase, state, image = self._read_and_process_server_response() assert agent_phase == GamePhase.OBSERVE_STATE, "Expecting OBSERVE_STATE from GVGAI, but received %s" % GamePhase( agent_phase) self.io.writeToServer(AgentPhase.OBSERVE_STATE) return state, image
def _start(self): # Firstly we should receive a choose-level state game_phase, _, _ = self._read_and_process_server_response() assert game_phase == GamePhase.START_STATE, "Expecting START_STATE from GVGAI, but received %s" % GamePhase( game_phase) self.io.writeToServer(AgentPhase.START_STATE)
def _read_and_process_server_response(self): game_phase_bytes, data_bytes = self.io.readFromServer() game_phase = GamePhase(int.from_bytes(game_phase_bytes, 'big')) state, image = self._process_data(data_bytes) return game_phase, state, image