def step(self, command: str) -> Tuple[GlulxGameState, float, bool]: if not self.game_running: raise GameNotRunningError() command = command.strip() output = self._send(command) if output is None: raise GameNotRunningError() self.game_state = self.game_state.update(command, output) self.game_state.has_timeout = not self.game_running return self.game_state, self.game_state.score, self.game_state.game_ended
def step(self, command: str) -> str: if not self.game_running: raise GameNotRunningError() self.state = GameState() self.state.last_command = command.strip() self.state.raw = self._send(self.state.last_command) if self.state.raw is None: raise GameNotRunningError() self.state.feedback = _strip_input_prompt_symbol(self.state.raw) self.state.score = 0 # Default value. self.state.done = False # Default value. return self.state, self.state.score, self.state.done
def reset(self): if not self.game_running: raise GameNotRunningError( "Call env.load(gamefile) before env.reset().") self.state = GameState() self.state.raw, _ = self._jericho.reset() self._gather_infos() self._reset = True return self.state
def step(self, command): if not self.game_running: raise GameNotRunningError() self.state = GameState() self.state.last_command = command.strip() res = self._jericho.step(self.state.last_command) # As of Jericho >= 2.1.0, the reward is returned instead of the score. self.state.raw, _, self.state.done, _ = res self._gather_infos() return self.state, self.state.score, self.state.done
def _send(self, command: str) -> None: if self._game_process.poll() is not None: raise GameNotRunningError() line = self._read_output(nb_retries=1) if len(line) > 0: # Make sure we have read everything in stdout before sending a command. # Check for concurrency issues. raise Exception("***Previous output hasn't been read entirely!!!") self._game_process.stdin.write(command + '\n')
def step(self, command): if not self.game_running: raise GameNotRunningError() command = command.strip() output, _, _, _ = self._jericho.step(command) self.game_state = self.game_state.update(command, output) self.game_state._score = self._jericho.get_score() self.game_state._max_score = self._jericho.get_max_score() self.game_state._has_won = self._jericho.victory() self.game_state._has_lost = self._jericho.game_over() return self.game_state, self.game_state.score, self.game_state.game_ended