def run_game(map_path, player1dir, player2dir, replay_dir, docker, terminal_viewer, extra_delay, max_memory, initial_time, per_frame_time, proxy_test, working_dir): args = {} args['dir_p1'] = player1dir args['dir_p2'] = player2dir args['docker'] = docker # TODO: Will cause name collisions if multiple instances run at the same time! args['replay_filename'] = os.path.join( replay_dir, "replay_" + str(len(os.listdir(replay_dir))) + replay_extension) # Make sure filename is used. Important if multiple instances are running at the same time f = open(args['replay_filename'], "w") f.write("") f.close() args['player_memory'] = max_memory args['player_cpu'] = 20 args['time_pool'] = initial_time args['time_additional'] = per_frame_time args['use_viewer'] = False args['terminal_viewer'] = terminal_viewer args['extra_delay'] = extra_delay args['map_name'] = map_path args['map'] = cli.get_map(map_path) args['working_dir'] = working_dir if terminal_viewer and sys.platform == 'win32' and not CINIT: print( 'To get pretty output with -tv on windows, run `py -3 -m pip install colorama`' ) (game, sandboxes, sock_file) = cli.create_game(args) if proxy_test: import proxyuploader up = proxyuploader.ProxyUploader() up.game_id = 12312 up.blue_id = 100 up.blue_id = 1000 up.game = game try: winner = cli.run_game(game, sandboxes, args, sock_file) finally: cli.cleanup(sandboxes, args, sock_file) if proxy_test: up.done = True print("Winner is player " + str(1 if winner == 'player1' else 2))
BUSY = False DB_LOCK = False GAMES_RUN = [] s3 = boto3.resource('s3') bucket = s3.Bucket(os.environ['BUCKET_NAME']) def random_key(length): return ''.join([ random.choice(string.ascii_letters + string.digits + string.digits) for _ in range(length) ]) PROXY_UPLOADER = proxyuploader.ProxyUploader() def end_game(data, winner, match_file, logs): global BUSY global DB_LOCK BUSY = False status = -1 if winner == 'player1': status = 'redwon' elif winner == 'player2': status = 'bluewon' replay_key = 'replays/' + str(data['id']) + '.bc18'