Ejemplo n.º 1
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:
            raise ValueError(
                "Cannot deserialize a TextWorld version {} game, expected version {}"
                .format(version, cls._SERIAL_VERSION))

        world = World.deserialize(data["world"])
        game = cls(world)
        game.grammar = Grammar(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.kb = KnowledgeBase.deserialize(data["KB"])
        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
Ejemplo n.º 2
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.
        """
        world = World.deserialize(data["world"])
        game = cls(world)
        game.grammar = Grammar(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.kb = KnowledgeBase.deserialize(data["KB"])
        game.metadata = data.get("metadata", {})
        game._objective = data.get("objective", None)
        return game