def build(self, validate: bool = True) -> Game: """ Create a `Game` instance given the defined facts. Parameters ---------- validate : optional If True, check if the game is valid, i.e. respects all constraints. Returns ------- Generated game. """ if validate: self.validate() # Validate the state of the world. world = World.from_facts(self.facts, kb=self._kb) game = Game(world, quests=self.quests) # Keep names and descriptions that were manually provided. for k, var_infos in game.infos.items(): if k in self._entities: game.infos[k] = self._entities[k].infos # Use text grammar to generate name and description. grammar = Grammar(self.options.grammar, rng=np.random.RandomState( self.options.seeds["grammar"])) game.change_grammar(grammar) game.metadata["desc"] = "Generated with textworld.GameMaker." self._game = game # Keep track of previous build. return self._game
def build(self, validate: bool = True) -> Game: """ Create a `Game` instance given the defined facts. Parameters ---------- validate : optional If True, check if the game is valid, i.e. respects all constraints. Returns ------- Generated game. """ if validate: self.validate() # Validate the state of the world. world = World.from_facts(self.facts) game = Game(world, quests=self._quests) # Keep names and descriptions that were manually provided. for k, var_infos in game.infos.items(): if k in self._entities: var_infos.name = self._entities[k].name var_infos.desc = self._entities[k].desc # If we can, reuse information generated during last build. if self._game is not None and k in self._game.infos: # var_infos.desc = self._game.infos[k].desc var_infos.name = self._game.infos[k].name var_infos.adj = self._game.infos[k].adj var_infos.noun = self._game.infos[k].noun var_infos.room_type = self._game.infos[k].room_type # Generate text for recently added objects. game.change_grammar(self.grammar) game.metadata["desc"] = "Generated with textworld.GameMaker." self._game = game # Keep track of previous build. return self._game