def appengine_main(ais, appengine_file_name=None, tournament_key=None): from google.appengine.api import files from appengine.appengine import record_game_to_db, mark_timed_out_ai from google.appengine.runtime import DeadlineExceededError ai_module.clear_ai_colors() start_time = time.time() if not appengine_file_name: appengine_file_name = files.blobstore.create(mime_type='text/html') settings.JS_REPLAY_FILENAME = appengine_file_name world_turns = [] w = world.World() turns_left = settings.END_GAME_TURNS deadlined = False for ai_class in ais: ai_player = w.addAI(ai_class) ai_module.generate_ai_color(ai_player) try: for i in xrange(settings.GAME_LENGTH): w.spinAI() if w.Turn(): if turns_left > 0: turns_left -= 1 else: break t = w.dumpTurnToDict(shorten=True) s = w.dumpScores() world_turns.append((t,s)) if len(world_turns) >= settings.BUFFER_SIZE: with files.open(appengine_file_name, 'a') as replay_file: settings.JS_REPLAY_FILE = replay_file jsplayer.save_world_turns(world_turns) replay_file.close() world_turns = [] gc.collect() log.info("Finished simulating the world") except KeyboardInterrupt, e: mark_timed_out_ai(w) raise
def appengine_main(ais, appengine_file_name=None, tournament_key=None): from appengine.appengine import gcs, BUCKET from appengine.appengine import record_game_to_db, mark_timed_out_ai from google.appengine.runtime import DeadlineExceededError import uuid ai_module.clear_ai_colors() start_time = time.time() if not appengine_file_name: appengine_file_name = str(uuid.uuid4()) replay_blob_key = appengine_file_name appengine_file_name = "/%s/%s" % (BUCKET, appengine_file_name) settings.JS_REPLAY_FILENAME = appengine_file_name world_turns = [] w = world.World() turns_left = settings.END_GAME_TURNS deadlined = False for ai_class in ais: ai_player = w.addAI(ai_class) ai_module.generate_ai_color(ai_player) try: for i in xrange(settings.GAME_LENGTH): w.spinAI() if w.Turn(): if turns_left > 0: turns_left -= 1 else: break t = w.dumpTurnToDict(shorten=True) s = w.dumpScores() world_turns.append((t, s)) log.info("Finished simulating the world") except KeyboardInterrupt, e: mark_timed_out_ai(w) raise
def appengine_main(ais, appengine_file_name=None, tournament_key=None): from appengine.appengine import gcs, BUCKET from appengine.appengine import record_game_to_db, mark_timed_out_ai from google.appengine.runtime import DeadlineExceededError import uuid ai_module.clear_ai_colors() start_time = time.time() if not appengine_file_name: appengine_file_name = str(uuid.uuid4()) replay_blob_key = appengine_file_name appengine_file_name = "/%s/%s" % (BUCKET, appengine_file_name) settings.JS_REPLAY_FILENAME = appengine_file_name world_turns = [] w = world.World() turns_left = settings.END_GAME_TURNS deadlined = False for ai_class in ais: ai_player = w.addAI(ai_class) ai_module.generate_ai_color(ai_player) try: for i in xrange(settings.GAME_LENGTH): w.spinAI() if w.Turn(): if turns_left > 0: turns_left -= 1 else: break t = w.dumpTurnToDict(shorten=True) s = w.dumpScores() world_turns.append((t,s)) log.info("Finished simulating the world") except KeyboardInterrupt, e: mark_timed_out_ai(w) raise
if turns_left > 0: turns_left -= 1 else: break t = w.dumpTurnToDict(shorten=True) s = w.dumpScores() world_turns.append((t, s)) log.info("Finished simulating the world") except KeyboardInterrupt, e: mark_timed_out_ai(w) raise except DeadlineExceededError, e: mark_timed_out_ai(w) deadlined = True except Exception, e: traceback.print_exc() finally: for ai in w.AI: log.info("%s:%s", ai.__class__, ai.score) if not deadlined: with gcs.open(appengine_file_name, 'w', content_type='text/html') as replay_file: settings.JS_REPLAY_FILE = replay_file if world_turns: jsplayer.save_world_turns(world_turns) # Save the world information to an output file. if settings.JS_REPLAY_FILE or settings.JS_REPLAY_FILENAME:
if turns_left > 0: turns_left -= 1 else: break t = w.dumpTurnToDict(shorten=True) s = w.dumpScores() world_turns.append((t,s)) log.info("Finished simulating the world") except KeyboardInterrupt, e: mark_timed_out_ai(w) raise except DeadlineExceededError, e: mark_timed_out_ai(w) deadlined = True except Exception, e: traceback.print_exc() finally: for ai in w.AI: log.info("%s:%s", ai.__class__, ai.score) if not deadlined: with gcs.open(appengine_file_name, 'w', content_type='text/html') as replay_file: settings.JS_REPLAY_FILE = replay_file if world_turns: jsplayer.save_world_turns(world_turns) # Save the world information to an output file. if settings.JS_REPLAY_FILE or settings.JS_REPLAY_FILENAME: jsplayer.end_world(w.dumpWorldToDict())