예제 #1
0
 def test_serialization(self):
     options = GrammarOptions(theme="dummy",
                              include_adj=True,
                              names_to_exclude=["name1", "name1", "name2"])
     data = options.serialize()
     json_data = json.dumps(data)
     options2 = GrammarOptions.deserialize(json.loads(json_data))
     assert options == options2
예제 #2
0
def main():
    args = parse_args()

    options = GrammarOptions()
    options.theme = args.theme
    vocab = extract_vocab(options)

    print("Vocab size: {} words".format(len(vocab)))

    with open(args.output, "w") as f:
        f.write("\n".join(vocab))
예제 #3
0
    def deserialize(cls, data: Mapping) -> "Game":
        """ Creates a `Game` from serialized data.

        Args:
            data: Serialized data with the needed information to build a
                  `Game` object.
        """

        version = data.get("version", cls._SERIAL_VERSION)
        if version != cls._SERIAL_VERSION:
            msg = "Cannot deserialize a TextWorld version {} game, expected version {}"
            raise ValueError(msg.format(version, cls._SERIAL_VERSION))

        kb = KnowledgeBase.deserialize(data["KB"])
        world = World.deserialize(data["world"], kb=kb)
        game = cls(world)
        game.grammar_options = GrammarOptions(data["grammar"])
        game.quests = tuple([Quest.deserialize(d) for d in data["quests"]])
        game._infos = {k: EntityInfo.deserialize(v) for k, v in data["infos"]}
        game.metadata = data.get("metadata", {})
        game._objective = data.get("objective", None)
        game.extras = data.get("extras", {})
        if "main_quest" in data:
            game.main_quest = Quest.deserialize(data["main_quest"])

        return game
예제 #4
0
    def __init__(self):
        self.chaining = ChainingOptions()
        self.grammar = GrammarOptions()
        self._seeds = None

        self.nb_rooms = 1
        self.nb_objects = 1
        self.quest_length = 1
        self.quest_breadth = 1
        self.force_recompile = False
예제 #5
0
파일: game.py 프로젝트: mhmohona/TextWorld
    def __init__(self):
        self.chaining = ChainingOptions()
        self.grammar = GrammarOptions()
        self._kb = None
        self._seeds = None

        self.nb_parallel_quests = 1
        self.nb_rooms = 1
        self.nb_objects = 1
        self.force_recompile = False
        self.file_ext = ".ulx"
        self.path = "./tw_games/"
 def _make_game(self, seeds):
     options = GameOptions()
     options.seeds = seeds
     options.grammar = GrammarOptions(self.grammar_flags)
     game = make_game_from_level(self.level, options)
     hashid = encode_seeds([self.game_generator_seed, self.level] +
                           [seeds[k] for k in sorted(seeds)])
     game_name = "{}_{}".format(self.spec.id, hashid)
     game_file = textworld.generator.compile_game(game,
                                                  path=pjoin(
                                                      "gen_games",
                                                      str(self.spec.id),
                                                      game_name + ".ulx"))
     return game_file
 def test_serialization(self):
     options = GrammarOptions()
     data = options.serialize()
     options2 = GrammarOptions.deserialize(data)
     assert options == options2