Exemple #1
0
def setup_preferences(kb, hero_info):
    hero_uid = uids.hero(hero_info.id)

    if hero_info.preferences_mob_id is not None:
        f_mob = fact_mob(
            mobs_storage.mobs_storage[hero_info.preferences_mob_id])
        if f_mob.uid not in kb:
            kb += f_mob
        kb += facts.PreferenceMob(object=hero_uid, mob=f_mob.uid)

    if hero_info.preferences_place_id is not None:
        f_place = fact_place(
            places_storage.places[hero_info.preferences_place_id])
        if f_place.uid not in kb:
            kb += f_place
        kb += facts.PreferenceHometown(object=hero_uid, place=f_place.uid)

    if hero_info.preferences_friend_id is not None:
        friend = persons_storage.persons[hero_info.preferences_friend_id]

        f_place = fact_place(friend.place)
        f_person = fact_person(friend)

        if f_place.uid not in kb:
            kb += f_place

        if f_person.uid not in kb:
            kb += f_person

        kb += facts.PreferenceFriend(object=hero_uid, person=f_person.uid)
        kb += facts.ExceptBadBranches(object=f_person.uid)

    if hero_info.preferences_enemy_id:
        enemy = persons_storage.persons[hero_info.preferences_enemy_id]

        f_place = fact_place(enemy.place)
        f_person = fact_person(enemy)

        if f_place.uid not in kb:
            kb += f_place

        if f_person.uid not in kb:
            kb += f_person

        kb += facts.PreferenceEnemy(object=hero_uid, person=f_person.uid)
        kb += facts.ExceptGoodBranches(object=f_person.uid)

    if hero_info.preferences_equipment_slot:
        kb += facts.PreferenceEquipmentSlot(
            object=hero_uid,
            equipment_slot=hero_info.preferences_equipment_slot.value)
 def test_except_good_branches__neutral(self):
     facts_list = [
         facts.Start(uid='start', type='test', nesting=0),
         facts.Jump(state_from='start', state_to='st_finish'),
         facts.Person(uid='person'),
         facts.ExceptGoodBranches(object='person')
     ]
     self.kb += facts_list
     self.kb += facts.Finish(uid='st_finish',
                             results={'person': RESULTS.NEUTRAL},
                             nesting=0,
                             start='start'),
     transformators.remove_restricted_states(self.kb)
     self.check_in_knowledge_base(self.kb, facts_list)
Exemple #3
0
    def test_enemy(self):
        place = self.place_2
        person = place.persons[0]

        self.hero.preferences.set_enemy(person)

        f_place = logic.fact_place(place)
        f_person = logic.fact_person(person)

        logic.setup_preferences(self.knowledge_base, self.get_hero_info())

        self.check_facts(
            places=[f_place],
            persons=[f_person],
            enemies=[
                facts.PreferenceEnemy(object=self.hero_uid,
                                      person=f_person.uid)
            ],
            good_branches=[facts.ExceptGoodBranches(object=f_person.uid)])
Exemple #4
0
    def test_enemy__second_setup(self):
        place = self.place_2
        person = place.persons[0]

        self.hero.preferences.set(heroes_relations.PREFERENCE_TYPE.ENEMY,
                                  person)

        f_place = logic.fact_place(place)
        f_person = logic.fact_person(person)

        self.knowledge_base += f_place
        self.knowledge_base += f_person

        logic.setup_preferences(self.knowledge_base, self.get_hero_info())

        self.check_facts(
            places=[f_place],
            persons=[f_person],
            enemies=[
                facts.PreferenceEnemy(object=self.hero_uid,
                                      person=f_person.uid)
            ],
            good_branches=[facts.ExceptGoodBranches(object=f_person.uid)])