def play_game_with_config(config, teams): team1, team2 = teams if config.tournament_log_folder: dumpfile = os.path.join( config.tournament_log_folder, "dump-{time}".format(time=time.strftime('%Y%m%d-%H%M%S'))) dump = dumpfile else: dump = None seed = str(random.randint(0, sys.maxsize)) res = libpelita.call_pelita( [config.team_spec(team1), config.team_spec(team2)], rounds=config.rounds, filter=config.filter, viewer=config.viewer, dump=dump, seed=seed) if dump: (_final_state, stdout, stderr) = res Path(dump + '.out').write_text(stdout) Path(dump + '.err').write_text(stderr) return res
def run_game(self, p1, p2): """Run a single game. This method runs a single game ``p1`` vs ``p2`` and internally stores the result. Parameters ---------- p1, p2 : int the indices of the players """ team_specs = [self.players[i]['path'] for i in (p1, p2)] final_state, stdout, stderr = libpelita.call_pelita(team_specs, rounds=self.rounds, filter=self.filter, viewer=self.viewer, dump=self.dump, seed=self.seed) if final_state['game_draw']: result = -1 else: result = final_state['team_wins'] logger.info('Final state: %r', final_state) logger.debug('Stdout: %r', stdout) if stderr: logger.warning('Stderr: %r', stderr) p1_name, p2_name = self.players[p1]['name'], self.players[p2]['name'] self.dbwrapper.add_gameresult(p1_name, p2_name, result, stdout, stderr)
def test_call_pelita(self): rounds = 200 viewer = 'ascii' filter = 'small' teams = ["pelita/player/StoppingPlayer", "pelita/player/StoppingPlayer"] (state, stdout, stderr) = libpelita.call_pelita(teams, rounds=rounds, viewer=viewer, filter=filter, dump=None, seed=None) assert state['team_wins'] is None assert state['game_draw'] is True teams = ["pelita/player/SmartEatingPlayer", "pelita/player/StoppingPlayer"] (state, stdout, stderr) = libpelita.call_pelita(teams, rounds=rounds, viewer=viewer, filter=filter, dump=None, seed=None) assert state['team_wins'] == 0 assert state['game_draw'] is None teams = ["pelita/player/StoppingPlayer", "pelita/player/SmartEatingPlayer"] (state, stdout, stderr) = libpelita.call_pelita(teams, rounds=rounds, viewer=viewer, filter=filter, dump=None, seed=None) assert state['team_wins'] == 1 assert state['game_draw'] is None
def test_call_pelita(self): rounds = 200 viewer = 'ascii' filter = 'small' teams = ["StoppingPlayer", "StoppingPlayer"] (state, stdout, stderr) = libpelita.call_pelita(teams, rounds=rounds, viewer=viewer, filter=filter, dump=None, seed=None) assert state['team_wins'] is None assert state['game_draw'] is True teams = ["SmartEatingPlayer", "StoppingPlayer"] (state, stdout, stderr) = libpelita.call_pelita(teams, rounds=rounds, viewer=viewer, filter=filter, dump=None, seed=None) assert state['team_wins'] == 0 assert state['game_draw'] is None teams = ["StoppingPlayer", "SmartEatingPlayer"] (state, stdout, stderr) = libpelita.call_pelita(teams, rounds=rounds, viewer=viewer, filter=filter, dump=None, seed=None) assert state['team_wins'] == 1 assert state['game_draw'] is None
def test_call_pelita(self): rounds = 200 viewer = 'ascii' filter = 'small' teams = [ "pelita/player/StoppingPlayer", "pelita/player/StoppingPlayer" ] (state, stdout, stderr) = libpelita.call_pelita(teams, rounds=rounds, viewer='null', filter=filter, dump=None, seed=None) assert state['team_wins'] is None assert state['game_draw'] is True # Quick assert that there is text in stdout assert len(stdout.split('\n')) == 6 teams = [ "pelita/player/SmartEatingPlayer", "pelita/player/StoppingPlayer" ] (state, stdout, stderr) = libpelita.call_pelita(teams, rounds=rounds, viewer=viewer, filter=filter, dump=None, seed=None) assert state['team_wins'] == 0 assert state['game_draw'] is None teams = [ "pelita/player/StoppingPlayer", "pelita/player/SmartEatingPlayer" ] (state, stdout, stderr) = libpelita.call_pelita(teams, rounds=rounds, viewer=viewer, filter=filter, dump=None, seed=None) assert state['team_wins'] == 1 assert state['game_draw'] is None
def test_call_pelita(self): rounds = 200 viewer = 'ascii' filter = 'small' teams = ["pelita/player/StoppingPlayer", "pelita/player/StoppingPlayer"] (state, stdout, stderr) = libpelita.call_pelita(teams, rounds=rounds, viewer='null', filter=filter, dump=None, seed=None) assert state['team_wins'] is None assert state['game_draw'] is True # Quick assert that there is text in stdout assert len(stdout.split('\n')) == 6 teams = ["pelita/player/SmartEatingPlayer", "pelita/player/StoppingPlayer"] (state, stdout, stderr) = libpelita.call_pelita(teams, rounds=rounds, viewer=viewer, filter=filter, dump=None, seed=None) assert state['team_wins'] == 0 assert state['game_draw'] is None teams = ["pelita/player/StoppingPlayer", "pelita/player/SmartEatingPlayer"] (state, stdout, stderr) = libpelita.call_pelita(teams, rounds=rounds, viewer=viewer, filter=filter, dump=None, seed=None) assert state['team_wins'] == 1 assert state['game_draw'] is None
def play_game_with_config(config, teams): team1, team2 = teams if config.tournament_log_folder: dumpfile = os.path.join( config.tournament_log_folder, "dump-{time}".format(time=time.strftime('%Y%m%d-%H%M%S'))) dump = dumpfile else: dump = None seed = str(random.randint(0, sys.maxsize)) return libpelita.call_pelita( [config.team_spec(team1), config.team_spec(team2)], rounds=config.rounds, filter=config.filter, viewer=config.viewer, dump=dump, seed=seed)
def play_game_with_config(config, teams): team1, team2 = teams if config.tournament_log_folder: dumpfile = os.path.join(config.tournament_log_folder, "dump-{time}".format(time=time.strftime('%Y%m%d-%H%M%S'))) dump = dumpfile else: dump = None seed = str(random.randint(0, sys.maxsize)) res = libpelita.call_pelita([config.team_spec(team1), config.team_spec(team2)], rounds=config.rounds, filter=config.filter, viewer=config.viewer, dump=dump, seed=seed) if dump: (_final_state, stdout, stderr) = res Path(dump + '.out').write_text(stdout) Path(dump + '.err').write_text(stderr) return res