def test_game_comparison(): rngs = {} rngs['rng_map'] = np.random.RandomState(1) rngs['rng_objects'] = np.random.RandomState(2) rngs['rng_quest'] = np.random.RandomState(3) rngs['rng_grammar'] = np.random.RandomState(4) game1 = make_game(world_size=5, nb_objects=5, quest_length=2, grammar_flags={}, rngs=rngs) rngs['rng_map'] = np.random.RandomState(1) rngs['rng_objects'] = np.random.RandomState(2) rngs['rng_quest'] = np.random.RandomState(3) rngs['rng_grammar'] = np.random.RandomState(4) game2 = make_game(world_size=5, nb_objects=5, quest_length=2, grammar_flags={}, rngs=rngs) assert game1 == game2 # Test __eq__ assert game1 in {game2} # Test __hash__ game3 = make_game(world_size=5, nb_objects=5, quest_length=2, grammar_flags={}, rngs=rngs) assert game1 != game3
def make(world_size: int = 1, nb_objects: int = 5, quest_length: int = 2, quest_breadth: int = 1, grammar_flags: Mapping = {}, seed: int = None, games_dir: str = "./gen_games/") -> Tuple[str, Game]: """ Makes a text-based game. Args: world_size: Number of rooms in the world. nb_objects: Number of objects in the world. quest_length: Minimum number of actions the quest requires to be completed. quest_breadth: Control how nonlinear a quest can be (1: linear). grammar_flags: Grammar options. seed: Random seed for the game generation process. games_dir: Path to the directory where the game will be saved. Returns: A tuple containing the path to the game file, and its corresponding Game's object. """ g_rng.set_seed(seed) game_name = "game_{}".format(seed) game = make_game(world_size, nb_objects, quest_length, quest_breadth, grammar_flags) game_file = compile_game(game, game_name, games_folder=games_dir, force_recompile=True) return game_file, game
def make(options: GameOptions) -> Tuple[str, Game]: """ Makes a text-based game. Arguments: options: For customizing the game generation (see :py:class:`textworld.GameOptions <textworld.generator.game.GameOptions>` for the list of available options). Returns: A tuple containing the path to the game file, and its corresponding Game's object. """ game = make_game(options) game_file = compile_game(game, options) return game_file, game
def make(options: GameOptions, path: str) -> Tuple[str, Game]: """ Makes a text-based game. Arguments: options: For customizing the game generation (see :py:class:`textworld.GameOptions <textworld.generator.game.GameOptions>` for the list of available options). path: Path of the compiled game (.ulx or .z8). Also, the source (.ni) and metadata (.json) files will be saved along with it. Returns: A tuple containing the path to the game file, and its corresponding Game's object. """ game = make_game(options) game_file = compile_game(game, path, force_recompile=options.force_recompile) return game_file, game