def change_grammar(self, grammar: Grammar) -> None: """ Changes the grammar used and regenerate all text. """ self.grammar = grammar _gen_commands = gen_commands_from_actions if self.grammar: from textworld.generator.inform7 import Inform7Game from textworld.generator.text_generation import generate_text_from_grammar inform7 = Inform7Game(self) _gen_commands = inform7.gen_commands_from_actions generate_text_from_grammar(self, self.grammar) for quest in self.quests: # TODO: should have a generic way of generating text commands from actions # instead of relying on inform7 convention. for event in quest.win_events: event.commands = _gen_commands(event.actions) if quest.win_events: quest.commands = quest.win_events[0].commands # Check if we can derive a global winning policy from the quests. if self.grammar: from textworld.generator.text_generation import describe_event policy = GameProgression(self).winning_policy if policy: mapping = {k: info.name for k, info in self._infos.items()} commands = [a.format_command(mapping) for a in policy] self.metadata["walkthrough"] = commands self.objective = describe_event(Event(policy), self, self.grammar)
def change_grammar(self, grammar: Grammar) -> None: """ Changes the grammar used and regenerate all text. """ from textworld.generator import inform7 from textworld.generator.text_generation import generate_text_from_grammar self.grammar = grammar generate_text_from_grammar(self, self.grammar) for quest in self.quests: # TODO: should have a generic way of generating text commands from actions # insteaf of relying on inform7 convention. quest.commands = inform7.gen_commands_from_actions( quest.actions, self.infos)
def change_grammar(self, grammar: Grammar) -> None: """ Changes the grammar used and regenerate all text. """ self.grammar = grammar if self.grammar is None: return from textworld.generator.inform7 import Inform7Game from textworld.generator.text_generation import generate_text_from_grammar inform7 = Inform7Game(self) generate_text_from_grammar(self, self.grammar) for quest in self.quests: # TODO: should have a generic way of generating text commands from actions # instead of relying on inform7 convention. quest.commands = inform7.gen_commands_from_actions(quest.actions)
def make_game_with(world, quests=None, grammar=None): game = Game(world, grammar, quests) if grammar is None: for var, var_infos in game.infos.items(): var_infos.name = var.name else: game = generate_text_from_grammar(game, grammar) return game
def change_grammar(self, grammar: Grammar) -> None: """ Changes the grammar used and regenerate all text. """ from textworld.generator.inform7 import Inform7Game from textworld.generator.text_generation import generate_text_from_grammar self.grammar = grammar _gen_commands = gen_commands_from_actions if self.grammar: inform7 = Inform7Game(self) _gen_commands = inform7.gen_commands_from_actions generate_text_from_grammar(self, self.grammar) for quest in self.quests: # TODO: should have a generic way of generating text commands from actions # instead of relying on inform7 convention. for event in quest.win_events: event.commands = _gen_commands(event.actions) quest.commands = quest.win_events[0].commands if self.main_quest: win_event = self.main_quest.win_events[0] self.main_quest.commands = _gen_commands(win_event.actions)