free_exits = [k for k, v in src.exits.items() if v.dest is None] if len(free_exits) == 0: continue dest = M.new_room() src_exit = rng_map.choice(free_exits) dest_exit = reverse_direction(src_exit) M.connect(src.exits[src_exit], dest.exits[dest_exit]) rooms.append(dest) # Generate the quest thats by collecting the coin. walkthrough.append("take coin") # TODO: avoid compiling the game at all (i.e. use the inference engine). M.set_quest_from_commands(walkthrough) game = M.build() game.metadata = metadata mode_choice = 0 if mode == "simple" else 1 uuid = "tw-coin_collector-{specs}-{grammar}-{seeds}" uuid = uuid.format(specs=encode_seeds((mode_choice, options.nb_rooms, options.quest_length)), grammar=options.grammar.uuid, seeds=encode_seeds([options.seeds[k] for k in sorted(options.seeds)])) game.metadata["uuid"] = uuid return game register(name="tw-coin_collector", desc="Generate a Coin Collector game", make=make, add_arguments=build_argparser)
chain = textworld.generator.sample_quest(world.state, options.chaining) # Add objects needed for the quest. world.state = chain.initial_state event = Event(chain.actions) quest = Quest( win_events=[event], fail_events=[ Event(conditions={Proposition("in", [wrong_obj, world.inventory])}) ]) grammar = textworld.generator.make_grammar(options.grammar, rng=rng_grammar) game = textworld.generator.make_game_with(world, [quest], grammar) game.metadata = metadata mode_choice = modes.index(mode) uuid = "tw-treasure_hunter-{specs}-{grammar}-{seeds}" uuid = uuid.format(specs=encode_seeds( (mode_choice, options.nb_rooms, options.quest_length)), grammar=options.grammar.uuid, seeds=encode_seeds( [options.seeds[k] for k in sorted(options.seeds)])) game.metadata["uuid"] = uuid return game register(name="tw-treasure_hunter", desc="Generate a Treasure Hunter game", make=make, add_arguments=build_argparser)
game.main_quest = M.new_quest_using_commands(walkthrough) game.change_grammar(game.grammar) if settings["goal"] == "detailed": # Use the detailed version of the objective. pass elif settings["goal"] == "brief": # Use a very high-level description of the objective. game.objective = objective elif settings["goal"] == "none": # No description of the objective. game.objective = "" game.metadata = metadata uuid = "tw-simple-r{rewards}+g{goal}+{dataset}-{flags}-{seeds}" uuid = uuid.format(rewards=str.title(settings["rewards"]), goal=str.title(settings["goal"]), dataset="test" if settings["test"] else "train", flags=options.grammar.uuid, seeds=encode_seeds( [options.seeds[k] for k in sorted(options.seeds)])) game.metadata["uuid"] = uuid return game # Register this simple game. register(name="tw-simple", desc="Generate simple challenge game", make=make_game, add_arguments=build_argparser)
help="Number of ingredients in the recipe. Default: %(default)s") group.add_argument("--take", type=int, default=0, metavar="INT", help="Number of ingredients to find. It must be less or equal to" " the value of `--recipe`. Default: %(default)s") group.add_argument("--go", type=int, default=1, choices=[1, 6, 9, 12], help="Number of locations in the game (1, 6, 9, or 12). Default: %(default)s") group.add_argument('--open', action="store_true", help="Whether containers/doors need to be opened.") group.add_argument('--cook', action="store_true", help="Whether some ingredients need to be cooked.") group.add_argument('--cut', action="store_true", help="Whether some ingredients need to be cut.") group.add_argument('--drop', action="store_true", help="Whether the player's inventory has limited capacity.") group.add_argument("--recipe-seed", type=int, default=0, metavar="INT", help="Random seed used for generating the recipe. Default: %(default)s") group.add_argument("--split", choices=["train", "valid", "test"], help="Control which foods can be used. Can either be" " 'train', 'valid', or 'test'." " Default: foods from all dataset splits can be used.") return parser register(name="tw-cooking", desc=("Generate cooking games similar to those used for the" " First TextWorld Problem (FTWP) competition (https://aka.ms/ftwp)."), make=make, add_arguments=build_argparser)