(args, num_times=1, seed=None)
return infos
Wrapper to help start the game
Wrapper to help start the game
Wrapper to help start the game
def run(args, num_times=1, seed=None):
    '''Wrapper to help start the game'''
    config = args.config
    record_pngs_dir = args.record_pngs_dir
    record_json_dir = args.record_json_dir
    agent_env_vars = args.agent_env_vars
    game_state_file = args.game_state_file
    render_mode = args.render_mode
    do_sleep = args.do_sleep

    agents = [
        helpers.make_agent_from_string(agent_string, agent_id)
        for agent_id, agent_string in enumerate(args.agents.split(','))
    ]

    env = make(config, agents, game_state_file, render_mode=render_mode)

    def _run(record_pngs_dir=None, record_json_dir=None):
        '''Runs a game'''
        print("Starting the Game.")
        if record_pngs_dir and not os.path.isdir(record_pngs_dir):
            os.makedirs(record_pngs_dir)
        if record_json_dir and not os.path.isdir(record_json_dir):
            os.makedirs(record_json_dir)

        obs = env.reset()
        done = False

        while not done:
            if args.render:
                env.render(
                    record_pngs_dir=record_pngs_dir,
                    record_json_dir=record_json_dir,
                    do_sleep=do_sleep)
            if args.render is False and record_json_dir:
                env.save_json(record_json_dir)
                time.sleep(1.0 / env._render_fps)
            actions = env.act(obs)
            obs, reward, done, info = env.step(actions)

        print("Final Result: ", info)
        if args.render:
            env.render(
                record_pngs_dir=record_pngs_dir,
                record_json_dir=record_json_dir,
                do_sleep=do_sleep)
            if do_sleep:
                time.sleep(5)
            env.render(close=True)
            
        if args.render is False and record_json_dir:
            env.save_json(record_json_dir)
            time.sleep(1.0 / env._render_fps)

        if record_json_dir:
            finished_at = datetime.now().isoformat()
            _agents = args.agents.split(',')
            utility.join_json_state(record_json_dir, _agents, finished_at,
                                    config, info)

        return info

    if seed is None:
        # Pick a random seed between 0 and 2^31 - 1
        seed = random.randint(0, np.iinfo(np.int32).max)
    np.random.seed(seed)
    random.seed(seed)
    env.seed(seed)

    infos = []
    times = []
    for i in range(num_times):
        start = time.time()

        record_pngs_dir_ = record_pngs_dir + '/%d' % (i+1) \
                           if record_pngs_dir else None
        record_json_dir_ = record_json_dir + '/%d' % (i+1) \
                           if record_json_dir else None
        infos.append(_run(record_pngs_dir_, record_json_dir_))

        times.append(time.time() - start)
        print("Game Time: ", times[-1])

    atexit.register(env.close)
    return infos
def run ( args , num_times = 1 , seed = None ) : config = args . config record_pngs_dir = args . record_pngs_dir record_json_dir = args . record_json_dir agent_env_vars = args . agent_env_vars game_state_file = args . game_state_file render_mode = args . render_mode do_sleep = args . do_sleep agents = [ helpers . make_agent_from_string ( agent_string , agent_id ) for agent_id , agent_string in enumerate ( args . agents . split ( ',' ) ) ] env = make ( config , agents , game_state_file , render_mode = render_mode ) def _run ( record_pngs_dir = None , record_json_dir = None ) : '''Runs a game''' print ( "Starting the Game." ) if record_pngs_dir and not os . path . isdir ( record_pngs_dir ) : os . makedirs ( record_pngs_dir ) if record_json_dir and not os . path . isdir ( record_json_dir ) : os . makedirs ( record_json_dir ) obs = env . reset ( ) done = False while not done : if args . render : env . render ( record_pngs_dir = record_pngs_dir , record_json_dir = record_json_dir , do_sleep = do_sleep ) if args . render is False and record_json_dir : env . save_json ( record_json_dir ) time . sleep ( 1.0 / env . _render_fps ) actions = env . act ( obs ) obs , reward , done , info = env . step ( actions ) print ( "Final Result: " , info ) if args . render : env . render ( record_pngs_dir = record_pngs_dir , record_json_dir = record_json_dir , do_sleep = do_sleep ) if do_sleep : time . sleep ( 5 ) env . render ( close = True ) if args . render is False and record_json_dir : env . save_json ( record_json_dir ) time . sleep ( 1.0 / env . _render_fps ) if record_json_dir : finished_at = datetime . now ( ) . isoformat ( ) _agents = args . agents . split ( ',' ) utility . join_json_state ( record_json_dir , _agents , finished_at , config , info ) return info if seed is None : # Pick a random seed between 0 and 2^31 - 1 seed = random . randint ( 0 , np . iinfo ( np . int32 ) . max ) np . random . seed ( seed ) random . seed ( seed ) env . seed ( seed ) infos = [ ] times = [ ] for i in range ( num_times ) : start = time . time ( ) record_pngs_dir_ = record_pngs_dir + '/%d' % ( i + 1 ) if record_pngs_dir else None record_json_dir_ = record_json_dir + '/%d' % ( i + 1 ) if record_json_dir else None infos . append ( _run ( record_pngs_dir_ , record_json_dir_ ) ) times . append ( time . time ( ) - start ) print ( "Game Time: " , times [ - 1 ] ) atexit . register ( env . close ) return infos