コード例 #1
0
ファイル: worker.py プロジェクト: pombreda/ants-pitlugabot
 def game(self, task, report_status=False):
     self.post_id += 1
     try:
         matchup_id = int(task["matchup_id"])
         log.info("Running game %s..." % matchup_id)
         options = None
         if 'game_options' in task:
             options = task["game_options"]
         if options == None:
             options = copy(server_info["game_options"])
         options["map"] = self.get_map(task['map_filename'])
         options["output_json"] = True
         game = Ants(options)
         bots = []
         for submission_id in task["submissions"]:
             submission_id = int(submission_id)
             if self.compile(submission_id, run_test=False):
                 submission_dir = self.submission_dir(submission_id)
                 run_cmd = compiler.get_run_cmd(submission_dir)
                 #run_dir = tempfile.mkdtemp(dir=server_info["compiled_path"])
                 bot_dir = os.path.join(submission_dir, 'bot')
                 bots.append((bot_dir, run_cmd))
                 #shutil.copytree(submission_dir, run_dir)
             else:
                 self.clean_download(submission_id)
                 raise Exception('bot', 'Can not compile bot %s' % submission_id)
         options['game_id'] = matchup_id
         log.debug((game.__class__.__name__, task['submissions'], options, matchup_id))
         # set worker debug logging
         if self.debug:
             options['verbose_log'] = sys.stdout
             replay_log = open('replay.json', 'w')
             options['replay_log'] = replay_log
             #options['stream_log'] = sys.stdout
             options['error_logs'] = [sys.stderr for _ in range(len(bots))]
             # options['output_logs'] = [sys.stdout, sys.stdout]
             # options['input_logs'] = [sys.stdout, sys.stdout]
         options['capture_errors'] = True
         result = run_game(game, bots, options)
         if self.debug:
             replay_log.close()
         log.debug(result)
         if 'game_id' in result:
             del result['game_id']
         result['matchup_id'] = matchup_id
         result['post_id'] = self.post_id
         if report_status:
             return self.cloud.post_result('api_game_result', result)
     except Exception as ex:
         log.debug(traceback.format_exc())
         result = {"post_id": self.post_id,
                   "matchup_id": matchup_id,
                   "error": str(ex) }
         success = self.cloud.post_result('api_game_result', result)
         # cleanup download dirs
         map(self.clean_download, map(int, task['submissions']))
         return success
コード例 #2
0
ファイル: worker.py プロジェクト: AliceTheCat/AntBot
 def functional_test(self, submission_id):
     self.post_id += 1
     log.info("Running functional test for %s" % submission_id)
     options = copy(server_info["game_options"])
     options['strict'] = True # kills bot on invalid inputs
     options['food'] = 'none'
     options['turns'] = 30
     log.debug(options)
     options["map"] = self.get_test_map()
     options['capture_errors'] = True
     game = Ants(options)
     if submission_id in self.download_dirs:
         bot_dir = self.download_dirs[submission_id]
     else:
         bot_dir = self.submission_dir(submission_id)
     bots = [(os.path.join(bot_dir, 'bot'),
              compiler.get_run_cmd(bot_dir)),
             (os.path.join(server_info['repo_path'],"ants","submission_test"), "python TestBot.py")]
     log.debug(bots)
     # set worker debug logging
     if self.debug:
         options['verbose_log'] = sys.stdout
         #options['stream_log'] = sys.stdout
         options['error_logs'] = [sys.stderr, sys.stderr]
         # options['output_logs'] = [sys.stdout, sys.stdout]
         # options['input_logs'] = [sys.stdout, sys.stdout]
     result = run_game(game, bots, options)
     if 'status' in result:
         if result['status'][1] in ('crashed', 'timeout', 'invalid'):
             if type(result['errors'][1]) == unicode:
                 errors_str = uni_to_ascii(result['errors'][1])
             else:
                 errors_str = '["'+ '","'.join(uni_to_ascii(e) for e in
                     result['errors'][1]) + '"]'
             msg = 'TestBot is not operational\n' + errors_str
             log.error(msg)
             return msg
         log.info(result['status'][0]) # player 0 is the bot we are testing
         if result['status'][0] in ('crashed', 'timeout', 'invalid'):
             if type(result['errors'][1]) == unicode:
                 errors_str = uni_to_ascii(result['errors'][0])
             else:
                 errors_str = '["'+ '","'.join(uni_to_ascii(e) for e in
                     result['errors'][0]) + '"]'
             log.info(errors_str)
             return result['errors'][0]
     elif 'error' in result:
         msg = 'Function Test failure: ' + result['error']
         log.error(msg)
         return msg
     return None
コード例 #3
0
ファイル: worker.py プロジェクト: zcoder/aichallenge
 def functional_test(self, submission_id):
     self.post_id += 1
     log.info("Running functional test for %s" % submission_id)
     options = copy(server_info["game_options"])
     options['strict'] = True  # kills bot on invalid inputs
     options['food'] = 'none'
     options['turns'] = 30
     log.debug(options)
     options["map"] = self.get_test_map()
     options['capture_errors'] = True
     game = Ants(options)
     if submission_id in self.download_dirs:
         bot_dir = self.download_dirs[submission_id]
     else:
         bot_dir = self.submission_dir(submission_id)
     bots = [(os.path.join(bot_dir, 'bot'), compiler.get_run_cmd(bot_dir)),
             (os.path.join(server_info['repo_path'], "ants",
                           "submission_test"), "python TestBot.py")]
     log.debug(bots)
     # set worker debug logging
     if self.debug:
         options['verbose_log'] = sys.stdout
         #options['stream_log'] = sys.stdout
         options['error_logs'] = [sys.stderr, sys.stderr]
         # options['output_logs'] = [sys.stdout, sys.stdout]
         # options['input_logs'] = [sys.stdout, sys.stdout]
     result = run_game(game, bots, options)
     if 'status' in result:
         if result['status'][1] in ('crashed', 'timeout', 'invalid'):
             if type(result['errors'][1]) == unicode:
                 errors_str = uni_to_ascii(result['errors'][1])
             else:
                 errors_str = '["' + '","'.join(
                     uni_to_ascii(e) for e in result['errors'][1]) + '"]'
             msg = 'TestBot is not operational\n' + errors_str
             log.error(msg)
             return msg
         log.info(result['status'][0])  # player 0 is the bot we are testing
         if result['status'][0] in ('crashed', 'timeout', 'invalid'):
             if type(result['errors'][1]) == unicode:
                 errors_str = uni_to_ascii(result['errors'][0])
             else:
                 errors_str = '["' + '","'.join(
                     uni_to_ascii(e) for e in result['errors'][0]) + '"]'
             log.info(errors_str)
             return result['errors'][0]
     elif 'error' in result:
         msg = 'Function Test failure: ' + result['error']
         log.error(msg)
         return msg
     return None
コード例 #4
0
 def game(self, task, report_status=False):
     self.post_id += 1
     try:
         matchup_id = int(task["matchup_id"])
         log.info("Running game %s..." % matchup_id)
         if 'options' in task:
             options = task["options"]
         else:
             options = server_info["game_options"]
         options["map"] = self.get_map(task['map_filename'])
         options["output_json"] = True
         game = Ants(options)
         bots = []
         for submission_id in task["players"]:
             if self.compile(submission_id):
                 submission_dir = self.submission_dir(submission_id)
                 run_cmd = compiler.get_run_cmd(submission_dir)
                 #run_dir = tempfile.mkdtemp(dir=server_info["submissions_path"])
                 bots.append((submission_dir, run_cmd))
                 #shutil.copytree(submission_dir, run_dir)
             else:
                 raise Exception('bot',
                                 'Can not compile bot %s' % submission_id)
         output_dir = os.path.join(server_info["root_path"], "games",
                                   str(matchup_id))
         if not os.path.exists(output_dir):
             try:
                 os.makedirs(output_dir)
             except:
                 pass
         options['output_dir'] = output_dir
         options['log_input'] = True
         options['log_output'] = True
         result = run_game(game, bots, options, matchup_id)
         result['matchup_id'] = task['matchup_id']
         result['post_id'] = self.post_id
         if report_status:
             self.cloud.post_result('api_game_result', result)
     except Exception as ex:
         import traceback
         traceback.print_exc()
         result = {
             "post_id": self.post_id,
             "matchup_id": matchup_id,
             "error": str(ex)
         }
         self.cloud.post_result('api_game_result', result)
コード例 #5
0
 def functional_test(self, submission_id):
     self.post_id += 1
     try:
         matchup_id = 0
         log.info("Running functional test for %s" % submission_id)
         options = server_info["game_options"]
         options["map"] = self.get_test_map()
         options["output_json"] = True
         game = Ants(options)
         submission_dir = self.submission_dir(submission_id)
         bots = [("../ants/submission_test/", "python TestBot.py"),
                 (submission_dir, compiler.get_run_cmd(submission_dir))]
         result = run_game(game, bots, options, matchup_id)
         log.info(result)
         return True
     except Exception as ex:
         log.error(traceback.format_exc())
         return False