Exemple #1
0
def college24_premade(clean):
    if not os.path.exists("college24_premade.db"):
        print("generating test data for query")
        from LiSE.examples.college import install
        with Engine('college24_premade.db', random_seed=69105) as eng:
            install(eng)
            for i in range(24):
                print(i)
                eng.next_turn()
    eng = Engine("college24_premade.db")
    yield eng
    eng.close()
Exemple #2
0
def test_keyframe_load_init(tempdir):
    """Can load a keyframe at start of branch, including locations"""
    eng = Engine(tempdir)
    inittest(eng)
    eng.branch = 'new'
    eng.snap_keyframe()
    eng.close()
    eng = Engine(tempdir)
    assert eng._things_cache.keyframe['physical', 'kobold'][
        eng.branch][eng.turn][eng.tick]
    assert 'kobold' in eng.character['physical'].thing
    assert (0, 0) in eng.character['physical'].place
    assert (0, 1) in eng.character['physical'].portal[0, 0]
    eng.close()
Exemple #3
0
 def setUp(self):
     self.engine = Engine("sqlite:///:memory:")
     self.graphmakers = (self.engine.new_character, )
     self.tempdir = tempfile.mkdtemp(dir='.')
     for f in ('trigger.py', 'prereq.py', 'action.py', 'function.py',
               'method.py', 'strings.json'):
         if os.path.exists(f):
             os.rename(f, os.path.join(self.tempdir, f))
Exemple #4
0
def test_facade_creation(name, data, stat, nodestat, statup, nodeup, edgeup):
    with Engine(connect_string='sqlite:///:memory:') as eng:
        char = eng.new_character(name, data, **stat)
        fac = char.facade()
        assert dict(fac.node) == dict(char.node)
        assert fac.node == char.node
        assert fac.edges == char.edges
        assert set(fac.edges) == set(char.edges)
        assert fac.stat == char.stat
        assert dict(fac.stat) == dict(char.stat)
Exemple #5
0
def test_char_creation(name, data, stat, nodestat, statup, nodeup, edgeup):
    with Engine(connect_string="sqlite:///:memory:") as eng:
        char = eng.new_character(name, data, **stat)
        assert set(char.node) == set(data)
        es = set()
        for k, v in data.items():
            for vv in v:
                es.add((k, vv))
        assert set(char.edges) == es
        assert char.stat == stat
Exemple #6
0
def college24_premade():
    codefiles = ('trigger.py', 'prereq.py', 'action.py', 'method.py', 'function.py', 'strings.json')
    tempdir = tempfile.mkdtemp(dir='.')
    for codefile in codefiles:
        if os.path.exists(codefile):
            os.rename(codefile, os.path.join(tempdir, codefile))
    if not os.path.exists("college24_premade.db"):
        print("generating test data for query")
        from LiSE.examples.college import install
        with Engine('college24_premade.db', random_seed=69105) as eng:
            install(eng)
            for i in range(24):
                print(i)
                eng.next_turn()
    eng = Engine("college24_premade.db")
    yield eng
    eng.close()
    for codefile in codefiles:
        if os.path.exists(os.path.join(tempdir, codefile)):
            os.rename(os.path.join(tempdir, codefile), codefile)
    os.rmdir(tempdir)
Exemple #7
0
    def setUp(self):
        """Start an engine, install the sim module, and run it a while.

        This gives us some world-state to test upon.

        """
        from logging import getLogger, FileHandler
        self.engine = Engine(":memory:")
        logger = getLogger('LiSE.engine')
        logger.setLevel('DEBUG')
        logger.addHandler(FileHandler('test.log'))
        sim.install(self.engine)
        for i in range(72):
            self.engine.next_tick()
        self.engine.commit()
Exemple #8
0
def character_updates(request):
    tempdir = tempfile.mkdtemp(dir='.')
    for f in ('trigger.py', 'prereq.py', 'action.py', 'function.py',
              'method.py', 'strings.json'):
        if os.path.exists(f):
            os.rename(f, os.path.join(tempdir, f))
    name, data, stat, nodestat, statup, nodeup, edgeup = request.param
    engine = Engine("sqlite:///:memory:")
    char = engine.new_character(name, data, **stat)
    update_char(char, node=nodestat)
    yield char, statup, nodeup, edgeup
    engine.close()
    for f in ('trigger.py', 'prereq.py', 'action.py', 'function.py',
              'method.py', 'strings.json'):
        if os.path.exists(f):
            os.remove(f)
        if os.path.exists(os.path.join(tempdir, f)):
            os.rename(os.path.join(tempdir, f), f)
    os.rmdir(tempdir)
Exemple #9
0
                if student not in student_body.stat['characters']:
                    student_body.stat['characters'].append(student)
                # Students' nodes are their brain cells.
                # They are useless if drunk or slow, but recover from both conditions a bit every hour.
                for k in range(0, 100):
                    cell = student.new_node('cell{}'.format(k),
                                            drunk=0,
                                            slow=0)
                    #  ``new_node`` is just an alias for ``new_place``;
                    #  perhaps more logical when the places don't really
                    #  represent potential locations
                    student.stat['xp'] = 0
                    student.stat['drunkard'] = eng.coinflip()
                    student.stat['lazy'] = eng.coinflip()
                # Apply these previously written rules to each student
                for rule in (drink, sloth):
                    student.rule(rule)
                # Apply these previously written rules to each brain cell
                for rule in (learn, sober_up, catch_up):
                    student.place.rule(rule)
    eng.snap_keyframe()


if __name__ == "__main__":
    from LiSE.engine import Engine
    with Engine(connect_string=":memory:") as eng:
        install(eng)
        for i in range(72):
            eng.next_turn()
            print(i)
Exemple #10
0
    go2kobold.prereqs = ['kobold_alive']

    @go2kobold.prereq
    def kobold_not_here(thing):
        return 'kobold' not in thing.location.content

    @dwarf.rule
    def wander(thing):
        dests = sorted(list(thing.character.place.keys()))
        dests.remove(thing['location'])
        thing.travel_to(thing.engine.choice(dests))

    @wander.trigger
    def standing_still(thing):
        return thing.next_location is None


if __name__ == '__main__':
    from LiSE.engine import Engine
    from os import remove
    try:
        remove('LiSEworld.db')
    except FileNotFoundError:
        pass
    with Engine('LiSEworld.db', random_seed=69105) as engine:
        inittest(engine, shrubberies=20, kobold_sprint_chance=.9)
        engine.commit()
        print('shrub_places beginning: {}'.format(
            engine.character['physical'].thing['kobold']['shrub_places']
        ))
Exemple #11
0
            for student in (student0, student1):
                if student not in student_body.stat['characters']:
                    student_body.stat['characters'].append(student)
                # Students' nodes are their brain cells.
                # They are useless if drunk or slow, but recover from both conditions a bit every hour.
                for k in range(0, 100):
                    cell = student.new_node('cell{}'.format(k),
                                            drunk=0,
                                            slow=0)
                    #  ``new_node`` is just an alias for ``new_place``;
                    #  perhaps more logical when the places don't really
                    #  represent potential locations
                    student.stat['xp'] = 0
                    student.stat['drunkard'] = eng.coinflip()
                    student.stat['lazy'] = eng.coinflip()
                # Apply these previously written rules to each student
                for rule in (drink, sloth):
                    student.rule(rule)
                # Apply these previously written rules to each brain cell
                for rule in (learn, sober_up, catch_up):
                    student.place.rule(rule)


if __name__ == "__main__":
    from LiSE.engine import Engine
    with Engine(":memory:") as eng:
        install(eng)
        for i in range(72):
            eng.next_turn()
            print(i)
Exemple #12
0
def mkengine(w='sqlite:///LiSEworld.db', *args, **kwargs):
    return Engine(worlddb=w, codedb='LiSEcode.db', *args, **kwargs)
Exemple #13
0
def college24_premade():
    directory = tempfile.mkdtemp('.')
    shutil.unpack_archive(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'college24_premade.tar.xz'), directory)
    with Engine(directory) as eng:
        yield eng
    shutil.rmtree(directory)
Exemple #14
0
def test():
    eng = Engine(":memory:")
    install(eng)
    for i in range(24):
        eng.next_tick()
Exemple #15
0
    def go2kobold(thing):
        thing.travel_to(thing.character.thing['kobold']['location'])

    go2kobold.trigger(aware)

    go2kobold.prereqs = ['kobold_alive']

    @go2kobold.prereq
    def kobold_not_here(thing):
        return 'kobold' not in thing.location.content

    @dwarf.rule
    def wander(thing):
        dests = sorted(list(thing.character.place.keys()))
        dests.remove(thing['location'])
        thing.travel_to(thing.engine.choice(dests))

    @wander.trigger
    def standing_still(thing):
        return thing.next_location is None


if __name__ == '__main__':
    from LiSE.engine import Engine
    from os import remove
    with Engine(random_seed=69105, clear=True) as engine:
        inittest(engine, shrubberies=20, kobold_sprint_chance=.9)
        engine.commit()
        print('shrub_places beginning: {}'.format(
            engine.character['physical'].thing['kobold']['shrub_places']))