def test_remove_unused_actors(self): self.kb += facts.Condition(uid="condition") self.kb += facts.Restriction(uid="restriction") self.kb += facts.Actor(uid="action_actor") self.kb += facts.Actor(uid="requirement_actor") self.kb += facts.Actor(uid="condition_actor") self.kb += facts.Actor(uid="removed_actor") self.kb += facts.State( uid="state", actions=[actions.GivePower(object="action_actor", power=1)], require=[requirements.LocatedIn(object="requirement_actor", place="requirement_actor")], ) self.kb += facts.Question( uid="question", condition=[requirements.LocatedIn(object="condition_actor", place="condition_actor")] ) transformators.remove_unused_actors(self.kb) self.assertFalse("removed_actor" in self.kb) self.assertFalse("condition" in self.kb) self.assertFalse("restriction" in self.kb) self.assertTrue("action_actor" in self.kb) self.assertTrue("requirement_actor" in self.kb) self.assertTrue("condition_actor" in self.kb) self.assertTrue("state" in self.kb) self.assertTrue("question" in self.kb)
def _create_random_quest_for_hero(hero_info, start_quests, without_restrictions=False): knowledge_base = get_knowledge_base(hero_info, without_restrictions=without_restrictions) selector = Selector(knowledge_base, QUESTS_BASE, social_connection_probability=c.QUESTS_SOCIAL_CONNECTIONS_FRACTION) hero_uid = uids.hero(hero_info.id) quests_facts = selector.create_quest_from_place(nesting=0, initiator_position=selector.place_for(objects=(hero_uid,)), allowed=start_quests, excluded=[], tags=('can_start', )) knowledge_base += quests_facts transformators.activate_events(knowledge_base) # TODO: after remove restricted states transformators.remove_restricted_states(knowledge_base) transformators.remove_broken_states(knowledge_base) # MUST be called after all graph changes transformators.determine_default_choices(knowledge_base, preferred_markers=hero_info.prefered_quest_markers) # MUST be called after all graph changes and on valid graph transformators.remove_unused_actors(knowledge_base) knowledge_base.validate_consistency(WORLD_RESTRICTIONS) knowledge_base.validate_consistency(QUEST_RESTRICTIONS) return knowledge_base
def _create_random_quest_for_hero(hero_info, start_quests, without_restrictions=False): knowledge_base = get_knowledge_base( hero_info, without_restrictions=without_restrictions) selector = Selector(knowledge_base, QUESTS_BASE, social_connection_probability=0) hero_uid = uids.hero(hero_info.id) quests_facts = selector.create_quest_from_place( nesting=0, initiator_position=selector.place_for(objects=(hero_uid, )), allowed=start_quests, excluded=[], tags=('can_start', )) knowledge_base += quests_facts transformators.activate_events( knowledge_base) # TODO: after remove restricted states transformators.remove_restricted_states(knowledge_base) transformators.remove_broken_states( knowledge_base) # MUST be called after all graph changes transformators.determine_default_choices( knowledge_base, preferred_markers=hero_info.prefered_quest_markers ) # MUST be called after all graph changes and on valid graph transformators.remove_unused_actors(knowledge_base) knowledge_base.validate_consistency(WORLD_RESTRICTIONS) knowledge_base.validate_consistency(QUEST_RESTRICTIONS) return knowledge_base
def test_remove_unused_actors(self): self.kb += facts.Condition(uid='condition') self.kb += facts.Restriction(uid='restriction') self.kb += facts.Actor(uid='action_actor') self.kb += facts.Actor(uid='requirement_actor') self.kb += facts.Actor(uid='condition_actor') self.kb += facts.Actor(uid='removed_actor') self.kb += facts.State( uid='state', actions=[actions.GivePower(object='action_actor', power=1)], require=[ requirements.LocatedIn(object='requirement_actor', place='requirement_actor') ]) self.kb += facts.Question(uid='question', condition=[ requirements.LocatedIn( object='condition_actor', place='condition_actor') ]) transformators.remove_unused_actors(self.kb) self.assertFalse('removed_actor' in self.kb) self.assertFalse('condition' in self.kb) self.assertFalse('restriction' in self.kb) self.assertTrue('action_actor' in self.kb) self.assertTrue('requirement_actor' in self.kb) self.assertTrue('condition_actor' in self.kb) self.assertTrue('state' in self.kb) self.assertTrue('question' in self.kb)
def test_remove_unused_actors(self): self.kb += facts.Condition(uid='condition') self.kb += facts.Restriction(uid='restriction') self.kb += facts.Actor(uid='action_actor') self.kb += facts.Actor(uid='requirement_actor') self.kb += facts.Actor(uid='condition_actor') self.kb += facts.Actor(uid='removed_actor') self.kb += facts.State(uid='state', actions=[actions.GiveReward(object='action_actor', scale=1, type='x')], require=[requirements.LocatedIn(object='requirement_actor', place='requirement_actor')]) self.kb += facts.Question(uid='question', condition=[requirements.LocatedIn(object='condition_actor', place='condition_actor')]) transformators.remove_unused_actors(self.kb) self.assertFalse('removed_actor' in self.kb) self.assertFalse('condition' in self.kb) self.assertFalse('restriction' in self.kb) self.assertTrue('action_actor' in self.kb) self.assertTrue('requirement_actor' in self.kb) self.assertTrue('condition_actor' in self.kb) self.assertTrue('state' in self.kb) self.assertTrue('question' in self.kb)