def engy(): codefiles = ('trigger.py', 'prereq.py', 'action.py', 'method.py', 'function.py', 'strings.json') tempdir = tempfile.mkdtemp(dir='.') for file in codefiles: if os.path.exists(file): os.rename(file, os.path.join(tempdir, file)) with Engine(":memory:") as eng: yield eng for file in codefiles: os.remove(file) if os.path.exists(os.path.join(tempdir, file)): os.rename(os.path.join(tempdir, file), file) os.rmdir(tempdir)
malaria_dead = 0 anemia_dead = 0 born = 0 while engine.turn < i: r = engine.next_turn() if not r: continue r = r[0] if r == 'malaria': malaria_dead += 1 elif r == 'anemia': anemia_dead += 1 elif r == 'mated': born += 1 print("On tick {}, {} critters were born; " "{} died of malaria, and {} of sickle cell anemia, " "leaving {} alive.".format( i, born, malaria_dead, anemia_dead, len(engine.character['species'].avatar['physical']))) print("Of the remaining {} creatures, {} have a sickle betaglobin.".format( len(species.avatar['physical']), sum(1 for critter in species.avatar['physical'].values() if critter['sickle_a'] or critter['sickle_b']))) try: remove('LiSEworld.db') except OSError: pass with Engine('LiSEworld.db', random_seed=69105) as engine: sickle_cell_test(engine)
def engy(tempdir): with Engine(tempdir) as eng: yield eng
# make an 8-way-connected grid physical.grid_2d_8graph(20, 20) empty = list(physical.place.values()) eng.shuffle(empty) # distribute 30 of each shape randomly among the empty places for i in range(1, 31): square.add_avatar(empty.pop().new_thing('square%i' % i, _image_paths=['atlas://polygons/meh_square'])) for i in range(1, 31): triangle.add_avatar(empty.pop().new_thing('triangle%i' % i, _image_paths=['atlas://polygons/meh_triangle'])) if __name__ == '__main__': import os from LiSE import Engine for stale in ('world.db', 'trigger.py', 'prereq.py', 'action.py', 'function.py', 'method.py'): if os.path.exists(stale): os.remove(stale) with Engine() as eng: with eng.batch(): install(eng) import sys if '--profile' in sys.argv: import cProfile def test(): with Engine('LiSEworld.db') as eng: for n in range(10): eng.next_turn() cProfile.run('test()', 'polygons.prof')
def test(): with Engine('LiSEworld.db') as eng: for n in range(10): eng.next_turn()
def test(): with Engine() as eng: for n in range(10): eng.next_turn()
def engy(clean): with Engine(":memory:") as eng: yield eng
empty = list(physical.place.values()) eng.shuffle(empty) # distribute 30 of each shape randomly among the empty places for i in range(1, 31): square.add_avatar(empty.pop().new_thing( 'square%i' % i, _image_paths=['atlas://polygons/meh_square'])) for i in range(1, 31): triangle.add_avatar(empty.pop().new_thing( 'triangle%i' % i, _image_paths=['atlas://polygons/meh_triangle'])) if __name__ == '__main__': import os from LiSE import Engine with Engine(clear=True) as eng, eng.batch(): install(eng) import sys if '--profile' in sys.argv: import cProfile def test(): with Engine() as eng: for n in range(10): eng.next_turn() cProfile.run('test()', 'polygons.prof') if '--time' in sys.argv: # only report the time it takes to actually simulate, # excluding startup time and such
def mkengine(w='LiSEworld.db'): return Engine(worlddb=w, codedb='LiSEcode.db')
"""Run at 5pm only.""" return engine.tick % 24 == 17 @work2home.prereq def at_work(engine, npc): """Run only when I'm at Work.""" return npc.avatar["physical"]["location"] == "work" while lise.tick < 76: test_advance(lise) lise.close() lise = Engine(worlddb='LiSEworld.db', codedb='LiSEcode.db') npc = lise.character["nonplayer"] while lise.tick < 119: test_advance(lise) phys = lise.character["physical"] phys.add_place("downtown") # when symmetrical, automagically create Downtown->Home portal with same attributes phys.add_portal("home", "downtown", symmetrical=True, km=2) assert (phys.portal["downtown"]["home"]["km"] == 2) phys.portal["downtown"]["home"]["fun"] = 100 assert (phys.portal["home"]["downtown"]["fun"] == 100) npc.avatar["physical"].travel_to("downtown", weight="km")
def mkengine(w='LiSEworld.db', caching=True, seed=None): return Engine(worlddb=w, codedb='LiSEcode.db', caching=caching, random_seed=seed)
malaria_dead = 0 anemia_dead = 0 born = 0 while engine.turn < i: r = engine.next_turn() if not r: continue r = r[0] if isinstance(r, Exception): raise r if 'malaria' in r: malaria_dead += 1 if 'anemia' in r: anemia_dead += 1 if 'mated' in r: born += 1 print("On turn {}, {} critters were born; " "{} died of malaria, and {} of sickle cell anemia, " "leaving {} alive.".format( i, born, malaria_dead, anemia_dead, len(engine.character['species'].avatar['physical']))) print("Of the remaining {} creatures, {} have a sickle betaglobin.".format( len(species.avatar['physical']), sum(1 for critter in species.avatar['physical'].values() if critter['sickle_a'] or critter['sickle_b']))) if __name__ == '__main__': with Engine(random_seed=69105, clear=True) as engine: sickle_cell_test(engine)