Example #1
0
    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())
Example #2
0
    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')
        ]
Example #3
0
    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()
        ])
Example #4
0
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(
    )  # проверяем, что для каждого окончания квеста указаны результаты для каждого его участника
]


# создаём задание
# эта функция может вызвать исключение questgen.exceptions.RollBackError и это её нормальное поведение
# исключение означает, что создать задание не получилось и надо повторить попытку
def create_quest():
Example #5
0
        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

    drawer = Drawer(knowledge_base=kb)
    drawer.draw('./svgs/%s.svg' % Quest.TYPE)