def main(): args = parse_args() game = Game.load(args.game) # Sample quests. rng = np.random.RandomState(args.seed) chains = [] rules_per_depth = {} for i in range(args.nb_quests): chain = sample_quest(game.world.state, rng, max_depth=args.quest_length, allow_partial_match=False, exceptions=[], rules_per_depth=rules_per_depth, backward=False) chains.append(chain) print_chains(chains, verbose=args.verbose) actions_tree = build_tree_from_chains(chains) # Convert tree to networkx graph/tree filename = "sample_tree.svg" G, labels = actions_tree.to_networkx() if len(G) > 0: tree = nx.bfs_tree(G, actions_tree.no) save_graph_to_svg(tree, labels, filename, backward=False) else: try: os.remove(filename) except: pass
def main(): args = parse_args() seen = {} seen_solution = {} for game_path in args.games: game_path = game_path.replace(".ulx", ".json") game = Game.load(game_path) solution = tuple(game.quests[0].commands) if game in seen: print("Duplicate found:") print(" > {}".format(game_path)) print(" > {}".format(seen[game])) print("-----") continue seen[game] = game_path if solution in seen_solution: print("Duplicate *solution* found:") print(" > {}".format(game_path)) print(" > {}".format(seen_solution[solution])) print("-----") continue seen_solution[solution] = game_path
def main(): args = parse_args() # Load game for which to sample quests for. game = Game.load(args.game.replace(".ulx", ".json")) options = ChainingOptions() options.backward = False options.max_depth = args.quest_length options.max_breadth = args.quest_breadth options.rules_per_depth = {} options.create_variables = False options.rng = np.random.RandomState(args.seed) # Sample quests. chains = [] for i in range(args.nb_quests): chain = sample_quest(game.world.state, options) chains.append(chain) inform7 = Inform7Game(game) print_chains(chains, inform7) # Convert chains to networkx graph/tree filename_world = pjoin(args.output, "sample_world.png") filename_tree = pjoin(args.output, "sample_tree.svg") filename_graph = pjoin(args.output, "sample_graph.svg") G, labels = build_tree_from_chains(chains, inform7) if len(G) > 0: image = visualize(game) image.save(filename_world) tree = nx.bfs_tree(G, "root") save_graph_to_svg(tree, labels, filename_tree) save_graph_to_svg(G, labels, filename_graph) else: try: os.remove(filename_world) os.remove(filename_tree) os.remove(filename_graph) except: pass