def test_one_choice(self): start = facts.Start(uid='start', type='test', nesting=0) choice_1 = facts.Choice(uid='choice_1') finish_1 = facts.Finish(uid='finish_1', results={}, nesting=0, start='start') finish_2 = facts.Finish(uid='finish_2', results={}, nesting=0, start='start') option_1 = facts.Option(state_from=choice_1.uid, state_to=finish_1.uid, type='opt_1', markers=()) option_2 = facts.Option(state_from=choice_1.uid, state_to=finish_2.uid, type='opt_2', markers=()) facts_list = [start, choice_1, finish_1, finish_2, option_1, option_2] self.kb += facts_list transformators.determine_default_choices(self.kb) self.check_in_knowledge_base(self.kb, facts_list) self.assertEqual(len(list(self.kb.filter(facts.OptionsLink))), 0) self.assertEqual(len(list(self.kb.filter(facts.ChoicePath))), 1) self.assertEqual( len(set([path.choice for path in self.kb.filter(facts.ChoicePath)])), 1) self.assertTrue( self.kb.filter(facts.ChoicePath).next().option in set( [option_1.uid, option_2.uid]))
def setUp(self): super(MultipleJumpsFromNormalStateTests, self).setUp() self.restriction = restrictions.MultipleJumpsFromNormalState() self.kb += [ facts.Start(uid='start', type='test', nesting=0), facts.Choice(uid='state_1'), facts.State(uid='state_2'), facts.Question(uid='state_3', condition=()), facts.Jump(state_from='state_2', state_to='state_3'), facts.Finish(start='start', uid='finish_1', results={}, nesting=0), facts.Finish(start='start', uid='finish_2', results={}, nesting=0), facts.Jump(state_from='start', state_to='state_1'), facts.Option(state_from='state_1', state_to='state_2', type='opt_1', markers=()), facts.Option(state_from='state_1', state_to='finish_1', type='opt_2', markers=()), facts.Answer(state_from='state_3', state_to='finish_1', condition=True), facts.Answer(state_from='state_3', state_to='finish_2', condition=False) ]
def test_multiple_tagged_jump(self): facts_list = [ facts.Start(uid='start', type='test', nesting=0), facts.Event(uid='event_tag', members=('st_finish_1', 'st_finish_2')) ] finishes = [ facts.Finish(uid='st_finish_1', results={}, nesting=0, start='start'), facts.Finish(uid='st_finish_2', results={}, nesting=0, start='start'), ] self.kb += facts_list self.kb += finishes transformators.activate_events(self.kb) self.check_in_knowledge_base(self.kb, facts_list) self.assertTrue( ('st_finish_1' in self.kb and 'st_finish_2' not in self.kb) or ('st_finish_2' in self.kb and 'st_finish_1' not in self.kb))
def construct_from_place(cls, nesting, selector, start_place): from questgen.quests.base_quest import ROLES initiator = selector.new_person(first_initiator=(nesting==0), restrict_places=False, places=(start_place.uid, )) receiver = selector.new_person(first_initiator=False) initiator_position = selector.place_for(objects=(initiator.uid,)) receiver_position = selector.place_for(objects=(receiver.uid,)) ns = selector._kb.get_next_ns() start = facts.Start(uid=ns+'start', type=cls.TYPE, nesting=nesting) choice_1 = facts.Choice(uid=ns+'choice_1') choice_2 = facts.Choice(uid=ns+'choice_2') finish_1_1 = facts.Finish(uid=ns+'finish_1_1', start=start.uid, results={initiator.uid: RESULTS.SUCCESSED, initiator_position.uid: RESULTS.FAILED, receiver.uid: RESULTS.SUCCESSED, receiver_position.uid: RESULTS.SUCCESSED}, nesting=nesting) finish_1_2 = facts.Finish(uid=ns+'finish_1_2', start=start.uid, results={initiator.uid: RESULTS.FAILED, initiator_position.uid: RESULTS.FAILED, receiver.uid: RESULTS.FAILED, receiver_position.uid: RESULTS.FAILED}, nesting=nesting) finish_2 = facts.Finish(uid=ns+'finish_2', start=start.uid, results={initiator.uid: RESULTS.SUCCESSED, initiator_position.uid: RESULTS.SUCCESSED, receiver.uid: RESULTS.FAILED, receiver_position.uid: RESULTS.FAILED}, nesting=nesting) participants = [facts.QuestParticipant(start=start.uid, participant=initiator.uid, role=ROLES.INITIATOR), facts.QuestParticipant(start=start.uid, participant=initiator_position.uid, role=ROLES.INITIATOR_POSITION), facts.QuestParticipant(start=start.uid, participant=receiver.uid, role=ROLES.RECEIVER), facts.QuestParticipant(start=start.uid, participant=receiver_position.uid, role=ROLES.RECEIVER_POSITION) ] quest_facts = [ start, choice_1, choice_2, finish_1_1, finish_1_2, finish_2, facts.Jump(state_from=start.uid, state_to=choice_1.uid), facts.Option(state_from=choice_1.uid, state_to=finish_2.uid, type='opt_1', markers=()), facts.Option(state_from=choice_1.uid, state_to=choice_2.uid, type='opt_2', markers=()), facts.Option(state_from=choice_2.uid, state_to=finish_1_1.uid, type='opt_2_1', markers=()), facts.Option(state_from=choice_2.uid, state_to=finish_1_2.uid, type='opt_2_2', markers=()) ] return participants + quest_facts
def test_linked_choices__linked_option_with_processed_choice(self): is_raised = False for i in xrange(100): kb = KnowledgeBase() start = facts.Start(uid='start', type='test', nesting=0) choice_1 = facts.Choice(uid='choice_1') choice_2 = facts.Choice(uid='choice_2') finish_1 = facts.Finish(uid='finish_1', results={}, nesting=0, start='start') finish_2 = facts.Finish(uid='finish_2', results={}, nesting=0, start='start') option_1 = facts.Option(state_from=choice_1.uid, state_to=finish_1.uid, type='opt_1', markers=()) option_2 = facts.Option(state_from=choice_1.uid, state_to=choice_2.uid, type='opt_2', markers=()) option_2_1 = facts.Option(state_from=choice_2.uid, state_to=finish_1.uid, type='opt_2_1', markers=()) option_2_2 = facts.Option(state_from=choice_2.uid, state_to=finish_2.uid, type='opt_2_2', markers=()) facts_list = [ start, facts.Jump(state_from=start.uid, state_to=choice_1.uid), choice_1, choice_2, finish_1, finish_2, option_1, option_2, option_2_1, option_2_2, facts.OptionsLink(options=(option_2.uid, option_2_2.uid)) ] kb += facts_list try: transformators.determine_default_choices(kb) except exceptions.LinkedOptionWithProcessedChoiceError: is_raised = True self.assertEqual(len(list(kb.filter(facts.ChoicePath))), 1) self.assertEqual( [path.choice for path in kb.filter(facts.ChoicePath)], [choice_2.uid]) self.assertEqual( [path.option for path in kb.filter(facts.ChoicePath)], [option_2_1.uid]) break self.assertFalse(is_raised)
def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position): hero = selector.heroes()[0] ns = selector._kb.get_next_ns() start = facts.Start(uid=ns+'start', type=cls.TYPE, nesting=nesting, description='Начало: помочь знакомому', require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid), requirements.LocatedIn(object=receiver.uid, place=receiver_position.uid)], actions=[actions.Message(type='intro')]) participants = [facts.QuestParticipant(start=start.uid, participant=initiator.uid, role=ROLES.INITIATOR), facts.QuestParticipant(start=start.uid, participant=receiver.uid, role=ROLES.RECEIVER) ] finish_successed = facts.Finish(uid=ns+'finish_successed', start=start.uid, results={ initiator.uid: RESULTS.SUCCESSED, receiver.uid: RESULTS.SUCCESSED}, nesting=nesting, description='помощь оказана', require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid)], actions=[actions.GiveReward(object=hero.uid, type='finish_successed')]) finish_failed = facts.Finish(uid=ns+'finish_failed', start=start.uid, results={ initiator.uid: RESULTS.FAILED, receiver.uid: RESULTS.FAILED}, nesting=nesting, description='не удалось помочь', actions=[actions.GiveReward(object=hero.uid, type='finish_failed')]) help_quest = selector.create_quest_from_person(nesting=nesting+1, initiator=receiver, tags=('can_continue',)) help_extra = [] for help_fact in logic.filter_subquest(help_quest, nesting): if isinstance(help_fact, facts.Start): help_extra.append(facts.Jump(state_from=start.uid, state_to=help_fact.uid, start_actions=[actions.Message(type='before_help')])) elif isinstance(help_fact, facts.Finish): if help_fact.results[receiver.uid] == RESULTS.SUCCESSED: help_extra.append(facts.Jump(state_from=help_fact.uid, state_to=finish_successed.uid, start_actions=[actions.Message(type='after_successed_help')])) else: help_extra.append(facts.Jump(state_from=help_fact.uid, state_to=finish_failed.uid)) subquest = facts.SubQuest(uid=ns+'help_subquest', members=logic.get_subquest_members(help_quest)) line = [ start, finish_successed, finish_failed, subquest ] line.extend(participants) line.extend(help_quest) line.extend(help_extra) return line
def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position): hero = selector.heroes()[0] ns = selector._kb.get_next_ns() start = facts.Start(uid=ns+'start', type=cls.TYPE, nesting=nesting, description='Начало: «сложное» задание', require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid)], actions=[actions.Message(type='intro')]) participants = [facts.QuestParticipant(start=start.uid, participant=receiver_position.uid, role=ROLES.RECEIVER_POSITION) ] arriving = facts.Choice(uid=ns+'arriving', description='Заплатить пошлину при прибытии в город или махнуть через стену', require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)]) tax = facts.Question(uid=ns+'tax', description='Хватит ли у героя денег на пошлину', condition=[requirements.HasMoney(object=hero.uid, money=100500)], actions=[actions.Message(type='tax_officer_conversation')]) finish_not_paid = facts.Finish(uid=ns+'finish_not_paid', start=start.uid, results={ receiver_position.uid: RESULTS.FAILED}, nesting=nesting, description='завершить задание', actions=[actions.GiveReward(object=hero.uid, type='finish')]) finish_paid = facts.Finish(uid=ns+'finish_paid', start=start.uid, results={ receiver_position.uid: RESULTS.SUCCESSED}, nesting=nesting, description='завершить задание', actions=[actions.GiveReward(object=hero.uid, type='finish')]) line = [ start, arriving, tax, finish_not_paid, finish_paid, facts.Jump(state_from=start.uid, state_to=arriving.uid), facts.Option(state_from=arriving.uid, state_to=finish_not_paid.uid, type='not_paid', markers=()), facts.Option(state_from=arriving.uid, state_to=tax.uid, type='pay_tax', markers=()), facts.Answer(state_from=tax.uid, state_to=finish_paid.uid, condition=True), facts.Answer(state_from=tax.uid, state_to=finish_not_paid.uid, condition=False) ] line.extend(participants) return line
def test_broken_linked_options(self): choice_1 = facts.Choice(uid='choice_1') choice_2 = facts.Choice(uid='choice_2') o_1_2 = facts.Option(state_from=choice_1.uid, state_to=choice_2.uid, type='o', markers=()) o_1_f1 = facts.Option(state_from=choice_1.uid, state_to='st_finish_1', type='o', markers=()) o_2_f1 = facts.Option(state_from=choice_2.uid, state_to='st_finish_1', type='o', markers=()) o_2_f2 = facts.Option(state_from=choice_2.uid, state_to='st_finish_2', type='o', markers=()) facts_list = [ facts.Start(uid='start', type='test', nesting=0), facts.Jump(state_from='start', state_to=choice_1.uid), choice_1, o_1_f1, facts.Finish(uid='st_finish_1', results={}, nesting=0, start='start') ] self.kb += facts_list broken = [ choice_2, o_1_2, o_2_f1, o_2_f2, facts.Finish(uid='st_finish_2', results={}, nesting=1, start='start') ] self.kb += broken self.kb += [facts.OptionsLink(options=[o_1_2.uid, o_2_f2.uid])] transformators.remove_broken_states(self.kb) self.check_in_knowledge_base(self.kb, facts_list) self.check_not_in_knowledge_base(self.kb, broken)
def setUp(self): super(ConnectedStateJumpGraphTests, self).setUp() self.restriction = restrictions.ConnectedStateJumpGraph() self.kb += [ facts.Start(uid='start', type='test', nesting=0), facts.State(uid='state_1'), facts.Start(uid='start_2', type='test', nesting=1), facts.Finish(start='start', uid='finish_1', results={}, nesting=0), facts.Finish(start='start', uid='finish_2', results={}, nesting=0), facts.Jump(state_from='start', state_to='state_1'), facts.Jump(state_from='state_1', state_to='start_2'), facts.Jump(state_from='state_1', state_to='finish_1'), facts.Jump(state_from='start_2', state_to='finish_2') ]
def test_remove_fake_finish(self): facts_list = [ facts.Start(uid='start', type='test', nesting=0), facts.Finish(uid='st_finish', results={}, nesting=0, start='start'), facts.Jump(state_from='start', state_to='st_finish') ] fake_finish = facts.Finish(uid='st_fake_finish', results={}, nesting=0, start='start') self.kb += [fake_finish] + facts_list transformators.remove_broken_states(self.kb) self.check_not_in_knowledge_base(self.kb, [fake_finish]) self.check_in_knowledge_base(self.kb, facts_list)
def test_more_then_one_finish(self): self.kb += self.finish self.kb += facts.Finish(start='start', uid='finish_2', results={}, nesting=0) self.restriction.validate(self.kb)
def setUp(self): super(FinishStateExistsTests, self).setUp() self.finish = facts.Finish(start='start', uid='finish', results={}, nesting=0) self.restriction = restrictions.FinishStateExists()
def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position): hero = selector.heroes()[0] ns = selector._kb.get_next_ns() start = facts.Start(uid=ns+'start', type=cls.TYPE, nesting=nesting, description=u'Начало: посетить родной города', require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid)], actions=[actions.Message(type='intro')]) participants = [facts.QuestParticipant(start=start.uid, participant=receiver_position.uid, role=ROLES.RECEIVER_POSITION) ] arriving = facts.State(uid=ns+'arriving', description=u'Прибытие в город', require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)]) action_choices = [facts.State(uid=ns+'drunk_song', description=u'спеть пьяную песню', actions=[actions.Message(type='drunk_song'), actions.DoNothing(type='drunk_song')]), facts.State(uid=ns+'stagger_streets', description=u'пошататься по улицам', actions=[actions.Message(type='stagger_streets'), actions.DoNothing(type='stagger_streets')]), facts.State(uid=ns+'chatting', description=u'пообщаться с друзьями', actions=[actions.Message(type='chatting'), actions.DoNothing(type='chatting')]), facts.State(uid=ns+'search_old_friends', description=u'искать старого друга', actions=[actions.Message(type='search_old_friends'), actions.DoNothing(type='search_old_friends')]), facts.State(uid=ns+'remember_names', description=u'вспоминать имена друзей', actions=[actions.Message(type='remember_names'), actions.DoNothing(type='remember_names')])] home_actions = random.sample(action_choices, 3) finish = facts.Finish(uid=ns+'finish', start=start.uid, results={ receiver_position.uid: RESULTS.SUCCESSED}, nesting=nesting, description=u'завершить посещение города', actions=[actions.GiveReward(object=hero.uid, type='finish')]) line = [ start, facts.Jump(state_from=start.uid, state_to=arriving.uid), arriving, facts.Jump(state_from=arriving.uid, state_to=home_actions[0].uid), facts.Jump(state_from=home_actions[0].uid, state_to=home_actions[1].uid), facts.Jump(state_from=home_actions[1].uid, state_to=home_actions[2].uid), facts.Jump(state_from=home_actions[2].uid, state_to=finish.uid), finish ] line.extend(home_actions) line.extend(participants) return line
def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position): ns = selector._kb.get_next_ns() start = facts.Start(uid=ns+'start', type=cls.TYPE, nesting=nesting, description=u'Начало: самый простой квест') participants = [facts.QuestParticipant(start=start.uid, participant=initiator.uid, role=ROLES.INITIATOR), facts.QuestParticipant(start=start.uid, participant=initiator_position.uid, role=ROLES.INITIATOR_POSITION), facts.QuestParticipant(start=start.uid, participant=receiver.uid, role=ROLES.RECEIVER), facts.QuestParticipant(start=start.uid, participant=receiver_position.uid, role=ROLES.RECEIVER_POSITION) ] finish_successed = facts.Finish(uid=ns+'finish_successed', start=start.uid, results={initiator.uid: RESULTS.SUCCESSED, initiator_position.uid: RESULTS.SUCCESSED, receiver.uid: RESULTS.SUCCESSED, receiver_position.uid: RESULTS.SUCCESSED}, nesting=nesting, description=u'завершить задание удачно') finish_failed = facts.Finish(uid=ns+'finish_failed', start=start.uid, results={initiator.uid: RESULTS.FAILED, initiator_position.uid: RESULTS.FAILED, receiver.uid: RESULTS.FAILED, receiver_position.uid: RESULTS.FAILED}, nesting=nesting, description=u'завершить задание плохо') event = facts.Event(uid=ns+'event', members=(finish_successed.uid, finish_failed.uid)) line = [ start, finish_successed, finish_failed, event, facts.Jump(state_from=start.uid, state_to=finish_successed.uid), facts.Jump(state_from=start.uid, state_to=finish_failed.uid) ] line.extend(participants) return line
def test_one_choice__no_markers(self): start = facts.Start(uid='start', type='test', nesting=0) choice_1 = facts.Choice(uid='choice_1') finish_1 = facts.Finish(uid='finish_1', results={}, nesting=0, start='start') finish_2 = facts.Finish(uid='finish_2', results={}, nesting=0, start='start') option_1 = facts.Option( state_from=choice_1.uid, state_to=finish_1.uid, type='opt_1', markers=[relations.OPTION_MARKERS.DISHONORABLE]) option_2 = facts.Option(state_from=choice_1.uid, state_to=finish_2.uid, type='opt_2', markers=[relations.OPTION_MARKERS.AGGRESSIVE]) facts_list = [start, choice_1, finish_1, finish_2, option_1, option_2] self.kb += facts_list for i in xrange(100): transformators.determine_default_choices( self.kb, preferred_markers=[relations.OPTION_MARKERS.HONORABLE]) self.check_in_knowledge_base(self.kb, facts_list) self.assertEqual(len(list(self.kb.filter(facts.OptionsLink))), 0) self.assertEqual(len(list(self.kb.filter(facts.ChoicePath))), 1) self.assertEqual( len( set([ path.choice for path in self.kb.filter(facts.ChoicePath) ])), 1) self.assertTrue( self.kb.filter(facts.ChoicePath).next().option in set( [option_1.uid, option_2.uid])) self.kb -= self.kb.filter(facts.ChoicePath)
def test_linked_choices__option_with_two_links(self): start = facts.Start(uid='start', type='test', nesting=0) choice_1 = facts.Choice(uid='choice_1') choice_2 = facts.Choice(uid='choice_2') finish_1 = facts.Finish(uid='finish_1', results={}, nesting=0, start='start') finish_2 = facts.Finish(uid='finish_2', results={}, nesting=0, start='start') option_1 = facts.Option(state_from=choice_1.uid, state_to=finish_1.uid, type='opt_1', markers=()) option_2 = facts.Option(state_from=choice_1.uid, state_to=choice_2.uid, type='opt_2', markers=()) option_2_1 = facts.Option(state_from=choice_2.uid, state_to=finish_1.uid, type='opt_2_1', markers=()) option_2_2 = facts.Option(state_from=choice_2.uid, state_to=finish_2.uid, type='opt_2_2', markers=()) facts_list = [ start, choice_1, choice_2, finish_1, finish_2, option_1, option_2, option_2_1, option_2_2, facts.OptionsLink(options=(option_1.uid, option_2_1.uid)), facts.OptionsLink(options=(option_2.uid, option_2_2.uid, option_1.uid)) ] self.kb += facts_list self.assertRaises(exceptions.OptionWithTwoLinksError, transformators.determine_default_choices, self.kb) self.check_in_knowledge_base(self.kb, facts_list) self.assertEqual(len(list(self.kb.filter(facts.ChoicePath))), 0)
def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position): hero = selector.heroes()[0] ns = selector._kb.get_next_ns() start = facts.Start(uid=ns+'start', type=cls.TYPE, nesting=nesting, description=u'Начало: навестить соратника', require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid)], actions=[actions.Message(type='intro')]) participants = [facts.QuestParticipant(start=start.uid, participant=receiver.uid, role=ROLES.RECEIVER) ] meeting = facts.State(uid=ns+'meeting', description=u'встреча с соратником', require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)]) finish_meeting = facts.Finish(uid=ns+'finish_meeting', start=start.uid, results={receiver.uid: RESULTS.SUCCESSED}, nesting=nesting, description=u'соратнику оказана помощь', require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)], actions=[actions.GiveReward(object=hero.uid, type='finish_meeting'), actions.GivePower(object=receiver.uid, power=1)]) help_quest = selector.create_quest_from_person(nesting=nesting+1, initiator=receiver, tags=('can_continue',)) help_extra = [] for help_fact in logic.filter_subquest(help_quest, nesting): if isinstance(help_fact, facts.Start): help_extra.append(facts.Jump(state_from=meeting.uid, state_to=help_fact.uid, start_actions=[actions.Message(type='before_help')])) elif isinstance(help_fact, facts.Finish): if help_fact.results[receiver.uid] == RESULTS.SUCCESSED: help_extra.append(facts.Jump(state_from=help_fact.uid, state_to=finish_meeting.uid, start_actions=[actions.Message(type='after_help')])) subquest = facts.SubQuest(uid=ns+'help_subquest', members=logic.get_subquest_members(help_quest)) line = [ start, facts.Jump(state_from=start.uid, state_to=meeting.uid), meeting, finish_meeting, subquest ] line.extend(participants) line.extend(help_quest) line.extend(help_extra) return line
def setUp(self): super(AllStatesHasJumpsTests, self).setUp() self.kb += [ facts.Start(uid='start', type='test', nesting=0), facts.State(uid='state_1'), facts.Finish(start='start', uid='finish_1', results={}, nesting=0), facts.Jump(state_from='start', state_to='state_1'), facts.Jump(state_from='state_1', state_to='finish_1') ] self.restriction = restrictions.AllStatesHasJumps()
def test_no_restricted_states(self): facts_list = [ facts.Start(uid='start', type='test', nesting=0), facts.Finish(uid='st_finish', results={}, nesting=0, start='start'), facts.Jump(state_from='start', state_to='st_finish') ] self.kb += facts_list transformators.remove_restricted_states(self.kb) self.check_in_knowledge_base(self.kb, facts_list)
def test_no_choices(self): facts_list = [ facts.Start(uid='start', type='test', nesting=0), facts.Finish(uid='st_finish', results={}, nesting=0, start='start'), facts.Jump(state_from='start', state_to='st_finish') ] self.kb += facts_list transformators.determine_default_choices(self.kb) self.check_in_knowledge_base(self.kb, facts_list) self.assertEqual(len(list(self.kb.filter(facts.OptionsLink))), 0)
def test_simple_tagged_jump(self): facts_list = [ facts.Start(uid='start', type='test', nesting=0), facts.Finish(uid='st_finish', results={}, nesting=0, start='start'), facts.Jump(state_from='start', state_to='st_finish'), facts.Event(uid='event_tag', members=('st_finish', )) ] self.kb += facts_list transformators.activate_events(self.kb) self.check_in_knowledge_base(self.kb, facts_list)
def setUp(self): super(RemoveBrokenQuestionStatesTests, self).setUp() self.question = facts.Question(uid='state_1', condition=()) self.answer_1 = facts.Answer(state_from='state_1', state_to='state_2', condition=True) self.answer_2 = facts.Answer(state_from='state_1', state_to='finish_1', condition=False) self.kb += [ facts.Start(uid='start', type='test', nesting=0), self.question, facts.State(uid='state_2'), facts.Finish(start='start', uid='finish_1', results={}, nesting=0), facts.Finish(start='start', uid='finish_2', results={}, nesting=0), facts.Jump(state_from='start', state_to='state_1'), self.answer_1, self.answer_2, facts.Jump(state_from='state_2', state_to='finish_2') ]
def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position): hero = selector.heroes()[0] ns = selector._kb.get_next_ns() start = facts.Start(uid=ns + 'start', type=cls.TYPE, nesting=nesting, description=u'Начало: простейшее задание', require=[ requirements.LocatedIn( object=hero.uid, place=initiator_position.uid) ], actions=[actions.Message(type='intro')]) participants = [ facts.QuestParticipant(start=start.uid, participant=receiver_position.uid, role=ROLES.RECEIVER_POSITION) ] arriving = facts.State(uid=ns + 'arriving', description=u'Прибытие в другой город', require=[ requirements.LocatedIn( object=hero.uid, place=receiver_position.uid) ]) facts.State(uid=ns + 'any_action', description=u'выполнить какое-то действие', actions=[actions.Message(type='do smth')]) finish = facts.Finish( uid=ns + 'finish', start=start.uid, results={receiver_position.uid: RESULTS.SUCCESSED}, nesting=nesting, description=u'завершить задание', actions=[actions.GiveReward(object=hero.uid, type='finish')]) line = [ start, facts.Jump(state_from=start.uid, state_to=arriving.uid), arriving, facts.Jump(state_from=arriving.uid, state_to=finish.uid), finish ] line.extend(participants) return line
def setUp(self): super(QuestionsConsistencyTests, self).setUp() self.restriction = restrictions.QuestionsConsistency() self.answer_1 = facts.Answer(state_from='state_1', state_to='state_2', condition=True) self.answer_2 = facts.Answer(state_from='state_1', state_to='finish_1', condition=False) self.kb += [ facts.Start(uid='start', type='test', nesting=0), facts.Question(uid='state_1', condition=()), facts.State(uid='state_2'), facts.Finish(start='start', uid='finish_1', results={}, nesting=0), facts.Finish(start='start', uid='finish_2', results={}, nesting=0), facts.Jump(state_from='start', state_to='state_1'), self.answer_1, self.answer_2, facts.Jump(state_from='state_2', state_to='finish_2') ]
def setUp(self): super(ChoicesConsistencyTests, self).setUp() self.restriction = restrictions.ChoicesConsistency() self.kb += [ facts.Start(uid='start', type='test', nesting=0), facts.Choice(uid='state_1'), facts.State(uid='state_2'), facts.Finish(start='start', uid='finish_1', results={}, nesting=0), facts.Finish(start='start', uid='finish_2', results={}, nesting=0), facts.Jump(state_from='start', state_to='state_1'), facts.Option(state_from='state_1', state_to='state_2', type='opt_1', markers=()), facts.Option(state_from='state_1', state_to='finish_1', type='opt_2', markers=()), facts.Jump(state_from='state_2', state_to='finish_2') ]
def test_no_tag(self): facts_list = [ facts.Start(uid='start', type='test', nesting=0), facts.Finish(uid='st_finish', results={}, nesting=0, start='start'), facts.Jump(state_from='start', state_to='st_finish'), facts.Event(uid='event_tag', members=()) ] self.kb += facts_list self.assertRaises(exceptions.NoEventMembersError, transformators.activate_events, self.kb) self.check_in_knowledge_base(self.kb, facts_list)
def setUp(self): super(FinishResultsConsistencyTests, self).setUp() self.restriction = restrictions.FinishResultsConsistency() self.finish_1 = facts.Finish(start='start_1', uid='finish_1', results={ 'p1': 0, 'p2': 0 }, nesting=0) self.finish_2 = facts.Finish(start='start_2', uid='finish_2', results={ 'p3': 0, 'p4': 0, 'p5': 0 }, nesting=0) self.kb += [ facts.Start(uid='start_1', type='test', nesting=0), facts.Start(uid='start_2', type='test', nesting=0), self.finish_1, self.finish_2, facts.QuestParticipant(start='start_1', participant='p1', role='role'), facts.QuestParticipant(start='start_1', participant='p2', role='role'), facts.QuestParticipant(start='start_2', participant='p3', role='role'), facts.QuestParticipant(start='start_2', participant='p4', role='role'), facts.QuestParticipant(start='start_2', participant='p5', role='role') ]
def setUp(self): self.kb = KnowledgeBase() self.hero = facts.Hero(uid='hero') self.start = facts.Start(uid='start', type='test', nesting=0) self.state_1 = facts.State(uid='state_1') self.state_2 = facts.State(uid='state_2') self.finish_1 = facts.Finish(start='start', uid='finish_1', results={}, nesting=0) self.kb += [ self.start, self.state_1, self.state_2, self.finish_1, self.hero] self.machine = Machine(knowledge_base=self.kb, interpreter=FakeInterpreter())
def test_except_bad_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.OnlyBadBranches(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)
def test_except_good_branches__successed(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.SUCCESSED}, nesting=0, start='start'), transformators.remove_restricted_states(self.kb) self.check_in_knowledge_base(self.kb, facts_list)