def setUp(self): self.kb = KnowledgeBase() # world self.kb += [ Place(uid='place_from'), Person(uid='person_from'), Place(uid='place_thought'), Place(uid='place_to'), Person(uid='person_to'), LocatedIn(object='person_from', place='place_from'), LocatedIn(object='person_to', place='place_to') ] # quest self.kb += [ Start(uid='start', nesting=0, type='simple_test', require=(requirements.LocatedIn(object='person_from', place='place_from'), requirements.LocatedIn(object='person_to', place='place_to'), requirements.LocatedIn(object='hero', place='place_from'))), State(uid='st_throught_place', require=(requirements.LocatedIn(object='hero', place='place_thought'), )), Finish(uid='st_finish', start='start', results={}, nesting=0, require=(requirements.LocatedIn(object='hero', place='place_to'), )), Jump(state_from='start', state_to='st_throught_place'), Jump(state_from='st_throught_place', state_to='st_finish') ] self.kb += [Hero(uid='hero')] self.kb.validate_consistency([ restrictions.SingleStartStateWithNoEnters(), restrictions.FinishStateExists(), restrictions.AllStatesHasJumps(), restrictions.SingleLocationForObject(), restrictions.ReferencesIntegrity(), restrictions.ConnectedStateJumpGraph(), restrictions.NoCirclesInStateJumpGraph(), restrictions.MultipleJumpsFromNormalState(), restrictions.ChoicesConsistency() ]) self.machine = machine.Machine(knowledge_base=self.kb, interpreter=FakeInterpreter())
def check_quest(self, quest_class): self.kb += quest_class.construct_from_place( nesting=0, selector=self.selector, start_place=self.selector.new_place(candidates=('place_1', ))) self.kb.validate_consistency([ restrictions.SingleStartStateWithNoEnters(), restrictions.FinishStateExists(), restrictions.AllStatesHasJumps(), restrictions.SingleLocationForObject(), restrictions.ReferencesIntegrity(), restrictions.ConnectedStateJumpGraph(), restrictions.NoCirclesInStateJumpGraph(), # restrictions.MultipleJumpsFromNormalState(), restrictions.ChoicesConsistency(), restrictions.QuestionsConsistency(), restrictions.FinishResultsConsistency(), restrictions.RequirementsConsistency(), restrictions.ActionsConsistency() ])
from questgen.quests.collect_debt import CollectDebt from questgen.quests.help_friend import HelpFriend from questgen.quests.interfere_enemy import InterfereEnemy from questgen.quests.help import Help from questgen.relations import PROFESSION # список ограничений для фактов о мире WORLD_RESTRICTIONS = [ restrictions.SingleLocationForObject(), restrictions.ReferencesIntegrity() ] # список ограничений для графа задания QUEST_RESTRICTIONS = [ restrictions.SingleStartStateWithNoEnters( ), # только одна начальная вершина для задания restrictions.FinishStateExists(), # существуют завершающие вершины restrictions.AllStatesHasJumps(), # существуют переходы из всех состояний restrictions.ConnectedStateJumpGraph(), # граф связаный restrictions.NoCirclesInStateJumpGraph(), # граф без циклов restrictions.MultipleJumpsFromNormalState( ), # каждая обычная вершина имеет только одну исходящую дугу restrictions.ChoicesConsistency(), # проверяем целостность развилок restrictions.QuestionsConsistency( ), # проверяем целостность условных узлов restrictions.FinishResultsConsistency( ) # проверяем, что для каждого окончания квеста указаны результаты для каждого его участника ] # создаём задание
facts.PreferenceMob(object='hero', mob='mob_1'), facts.PreferenceHometown(object='hero', place='place_2'), facts.PreferenceFriend(object='hero', person='person_4'), facts.PreferenceEnemy(object='hero', person='person_5'), facts.UpgradeEquipmentCost(money=777) ] selector = Selector(kb, qb) kb += Quest.construct_from_place( nesting=0, selector=selector, start_place=selector.new_place(candidates=('place_1', ))) try: kb.validate_consistency([ restrictions.SingleStartStateWithNoEnters(), restrictions.FinishStateExists(), restrictions.AllStatesHasJumps(), restrictions.SingleLocationForObject(), restrictions.ReferencesIntegrity(), restrictions.ConnectedStateJumpGraph(), restrictions.NoCirclesInStateJumpGraph(), # restrictions.MultipleJumpsFromNormalState(), restrictions.ChoicesConsistency(), # restrictions.QuestionsConsistency(), restrictions.FinishResultsConsistency() ]) pass except Exception: print('quesr %s is invalid' % Quest.TYPE) raise
def setUp(self): super(SingleStartStateWithNoEntersTests, self).setUp() self.start = facts.Start(uid='start', type='test', nesting=0) self.restriction = restrictions.SingleStartStateWithNoEnters()