def test_rules(): # Make sure the number of basic rules matches the number # of rules in rules.txt basic_rules = [k for k in data.get_rules().keys() if "-" not in k] assert len(basic_rules) == 19 for rule in data.get_rules().values(): infos = rule.serialize() loaded_rule = Rule.deserialize(infos) assert loaded_rule == rule
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"]) grammar = None if "grammar" in data: grammar = Grammar(data["grammar"]) quests = [Quest.deserialize(d) for d in data["quests"]] game = cls(world, grammar, quests) game._infos = {k: EntityInfo.deserialize(v) for k, v in data["infos"]} game.state = State.deserialize(data["state"]) game._rules = {k: Rule.deserialize(v) for k, v in data["rules"]} game._types = VariableTypeTree.deserialize(data["types"]) game.metadata = data.get("metadata", {}) return game
def test_rules(): for rule in KnowledgeBase.default().rules.values(): infos = rule.serialize() loaded_rule = Rule.deserialize(infos) assert loaded_rule == rule