def test_player_startup_gtp_commands(tc): comp = competitions.Competition('test') config = { 'players': { 't1': Player_config("test", startup_gtp_commands=["foo"]), 't2': Player_config("test", startup_gtp_commands=["foo bar baz"]), 't3': Player_config("test", startup_gtp_commands=[["foo", "bar", "baz"]]), 't4': Player_config( "test", startup_gtp_commands=["xyzzy test", ["foo", "bar", "baz"]]), } } comp.initialise_from_control_file(config) tc.assertListEqual(comp.players['t1'].startup_gtp_commands, [("foo", [])]) tc.assertListEqual(comp.players['t2'].startup_gtp_commands, [("foo", ["bar", "baz"])]) tc.assertListEqual(comp.players['t3'].startup_gtp_commands, [("foo", ["bar", "baz"])]) tc.assertListEqual(comp.players['t4'].startup_gtp_commands, [("xyzzy", ["test"]), ("foo", ["bar", "baz"])])
def test_competitor_change(tc): fx = Allplayall_fixture(tc) status = pickle.loads(pickle.dumps(fx.comp.get_status())) config2 = default_config() del config2['competitors'][2] comp2 = allplayalls.Allplayall('testcomp') comp2.initialise_from_control_file(config2) with tc.assertRaises(CompetitionError) as ar: comp2.set_status(status) tc.assertEqual(str(ar.exception), "competitor has been removed from control file") config3 = default_config() config3['players']['t4'] = Player_config("test4") config3['competitors'][2] = 't4' comp3 = allplayalls.Allplayall('testcomp') comp3.initialise_from_control_file(config3) with tc.assertRaises(CompetitionError) as ar: comp3.set_status(status) tc.assertEqual(str(ar.exception), "competitors have changed in the control file") config4 = default_config() config4['players']['t4'] = Player_config("test4") config4['competitors'].append('t4') comp4 = allplayalls.Allplayall('testcomp') comp4.initialise_from_control_file(config4) comp4.set_status(status)
def default_config(): return { 'players' : { 't1' : Player_config("test1"), 't2' : Player_config("test2"), }, 'board_size' : 13, 'komi' : 7.5, 'matchups' : [ Matchup_config('t1', 't2', alternating=True), ], }
def test_player_is_reliable_scorer(tc): comp = competitions.Competition('test') config = { 'players': { 't1': Player_config("test"), 't2': Player_config("test", is_reliable_scorer=False), 't3': Player_config("test", is_reliable_scorer=True), } } comp.initialise_from_control_file(config) tc.assertTrue(comp.players['t1'].is_reliable_scorer) tc.assertFalse(comp.players['t2'].is_reliable_scorer) tc.assertTrue(comp.players['t3'].is_reliable_scorer)
def test_player_stderr(tc): comp = competitions.Competition('test') config = { 'players': { 't1': Player_config("test"), 't2': Player_config("test", discard_stderr=True), 't3': Player_config("test", discard_stderr=False), } } comp.initialise_from_control_file(config) tc.assertIs(comp.players['t1'].discard_stderr, False) tc.assertEqual(comp.players['t2'].discard_stderr, True) tc.assertIs(comp.players['t3'].discard_stderr, False)
def default_config(): return { 'players': { 't1': Player_config("test1"), 't2': Player_config("test2"), 't3': Player_config("test3"), }, 'board_size': 13, 'komi': 7.5, 'competitors': [ Competitor_config('t1'), Competitor_config('t2'), 't3', ], }
def default_config(): return { 'board_size' : 13, 'komi' : 7.5, 'players' : { 'opp' : Player_config("test"), }, 'candidate_colour' : 'w', 'opponent' : 'opp', 'parameters' : [ Parameter_config( 'axisa', initial_mean = 0.5, initial_variance = 1.0, format = "axa %.3f"), Parameter_config( 'axisb', initial_mean = 50.0, initial_variance = 1000.0, transform = clip_axisb, format = "axb %.1f"), ], 'batch_size' : 3, 'samples_per_generation' : 4, 'number_of_generations' : 3, 'elite_proportion' : 0.1, 'step_size' : 0.8, 'make_candidate' : simple_make_candidate, }
def test_matchup_change(tc): fx = Playoff_fixture(tc) jobs = [fx.comp.get_game() for _ in range(8)] for i in [0, 2, 3, 4, 6, 7]: response = fake_response(jobs[i], ('b' if i in (0, 3) else 'w')) fx.comp.process_game_result(response) fx.check_screen_report(dedent("""\ t1 v t2 (6 games) board size: 13 komi: 7.5 wins black white t1 2 33.33% 1 25.00% 1 50.00% t2 4 66.67% 1 50.00% 3 75.00% 2 33.33% 4 66.67% """)) config2 = default_config() config2['players']['t3'] = Player_config("test3") config2['matchups'][0] = Matchup_config('t1', 't3', alternating=True) comp2 = playoffs.Playoff('testcomp') comp2.initialise_from_control_file(config2) status = pickle.loads(pickle.dumps(fx.comp.get_status())) with tc.assertRaises(CompetitionError) as ar: comp2.set_status(status) tc.assertEqual( str(ar.exception), "existing results for matchup 0 are inconsistent with control file:\n" "result players are t1,t2;\n" "control file players are t1,t3")
def default_config(): return { 'board_size': 13, 'komi': 7.5, 'players': { 'opp': Player_config("test"), }, 'candidate_colour': 'w', 'opponent': 'opp', 'exploration_coefficient': 0.2, 'initial_visits': 10, 'initial_wins': 5, 'parameters': [ Parameter_config('resign_at', scale=float, split=12, format="rsn@ %.2f"), Parameter_config('initial_wins', scale=mcts_tuners.LINEAR(0, 100), split=10, format="iwins %d"), ], 'make_candidate': simple_make_candidate, }
def test_player_cwd(tc): comp = competitions.Competition('test') comp.set_base_directory("/base") config = { 'players': { 't1': Player_config("test"), 't2': Player_config("test", cwd="/abs"), 't3': Player_config("test", cwd="rel/sub"), 't4': Player_config("test", cwd="."), 't5': Player_config("test", cwd="~/tmp/sub"), } } comp.initialise_from_control_file(config) tc.assertIsNone(comp.players['t1'].cwd) tc.assertEqual(comp.players['t2'].cwd, "/abs") tc.assertEqual(comp.players['t3'].cwd, "/base/rel/sub") tc.assertEqual(comp.players['t4'].cwd, "/base/.") tc.assertEqual(comp.players['t5'].cwd, os.path.expanduser("~") + "/tmp/sub")
def test_player_command(tc): comp = competitions.Competition('test') comp.set_base_directory("/base") config = { 'players': { 't1': Player_config("test"), 't2': Player_config("/bin/test foo"), 't3': Player_config(["bin/test", "foo"]), 't4': Player_config("~/test foo"), 't5': Player_config("~root"), } } comp.initialise_from_control_file(config) tc.assertEqual(comp.players['t1'].cmd_args, ["test"]) tc.assertEqual(comp.players['t2'].cmd_args, ["/bin/test", "foo"]) tc.assertEqual(comp.players['t3'].cmd_args, ["/base/bin/test", "foo"]) tc.assertEqual(comp.players['t4'].cmd_args, [os.path.expanduser("~") + "/test", "foo"]) tc.assertEqual(comp.players['t5'].cmd_args, ["~root"])
def test_bad_player(tc): comp = competitions.Competition('test') config = { 'players': { 't1': Player_config("test"), 't2': None, } } tc.assertRaisesRegexp(ControlFileError, "'players': bad value for 't2': not a Player", comp.initialise_from_control_file, config)
def test_get_player_checks(tc): comp = playoffs.Playoff('testcomp') config = default_config() config['players']['t3'] = Player_config("test3") config['matchups'].append(Matchup_config('t1', 't3', number_of_games=0), ), comp.initialise_from_control_file(config) checks = comp.get_player_checks() tc.assertEqual(len(checks), 2) tc.assertEqual(checks[0].board_size, 13) tc.assertEqual(checks[0].komi, 7.5) tc.assertEqual(checks[0].player.code, "t1") tc.assertEqual(checks[0].player.cmd_args, ['test1']) tc.assertEqual(checks[1].player.code, "t2") tc.assertEqual(checks[1].player.cmd_args, ['test2'])
def test_player_gtp_aliases(tc): comp = competitions.Competition('test') config = { 'players': { 't1': Player_config("test", gtp_aliases={ 'foo': 'bar', 'baz': 'quux' }), } } comp.initialise_from_control_file(config) tc.assertDictEqual(comp.players['t1'].gtp_aliases, { 'foo': 'bar', 'baz': 'quux' })
def test_player_config(tc): comp = competitions.Competition('test') p1 = comp.game_jobs_player_from_config('pp', Player_config("cmd")) tc.assertEqual(p1.code, 'pp') tc.assertEqual(p1.cmd_args, ["cmd"]) p2 = comp.game_jobs_player_from_config('pp', Player_config(command="cmd")) tc.assertEqual(p2.code, 'pp') tc.assertEqual(p2.cmd_args, ["cmd"]) tc.assertRaisesRegexp(Exception, "'command' not specified", comp.game_jobs_player_from_config, 'pp', Player_config()) tc.assertRaisesRegexp(Exception, "too many positional arguments", comp.game_jobs_player_from_config, 'pp', Player_config("cmd", "xxx")) tc.assertRaisesRegexp( Exception, "command specified as both positional and keyword argument", comp.game_jobs_player_from_config, 'pp', Player_config("cmd", command="cmd2")) tc.assertRaisesRegexp(Exception, "unknown argument 'unexpected'", comp.game_jobs_player_from_config, 'pp', Player_config("cmd", unexpected=3))
def simple_make_candidate(*args): if -1 in args: raise ValueError("oops") return Player_config("cand " + " ".join(map(str, args)))