コード例 #1
0
ファイル: cem_tuner_tests.py プロジェクト: mattheww/gomill
def test_random_candidate_colour(tc):
    comp = cem_tuners.Cem_tuner('cemtest')
    config = default_config()
    config['candidate_colour'] = 'random'
    random.seed(1002)
    comp.initialise_from_control_file(config)
    comp.set_clean_status()

    job1 = comp.get_game()
    tc.assertIsInstance(job1, Game_job)
    tc.assertEqual(job1.player_b.code, 'g0#0')
    tc.assertEqual(job1.player_w.code, 'opp')

    job2 = comp.get_game()
    tc.assertIsInstance(job2, Game_job)
    tc.assertEqual(job2.player_b.code, 'g0#1')
    tc.assertEqual(job2.player_w.code, 'opp')

    result1 = Game_result.from_score('b', 8.5)
    result1.set_players({'b' : 'g0#0', 'w' : 'opp'})
    response1 = Game_job_result()
    response1.game_id = job1.game_id
    response1.game_result = result1
    response1.engine_descriptions = {
        'opp' : Engine_description("opp engine", "v1.2.3", None),
        '#0'  : Engine_description("candidate engine", None, None),
        }
    response1.game_data = job1.game_data
    comp.process_game_result(response1)

    tc.assertEqual(comp.wins, [1, 0, 0, 0])
コード例 #2
0
ファイル: playoff_tests.py プロジェクト: mattheww/gomill
def test_play(tc):
    fx = Playoff_fixture(tc)
    tc.assertIsNone(fx.comp.description)

    job1 = fx.comp.get_game()
    tc.assertIsInstance(job1, Game_job)
    tc.assertEqual(job1.game_id, '0_0')
    tc.assertEqual(job1.player_b.code, 't1')
    tc.assertEqual(job1.player_w.code, 't2')
    tc.assertEqual(job1.board_size, 13)
    tc.assertEqual(job1.komi, 7.5)
    tc.assertEqual(job1.move_limit, 1000)
    tc.assertIs(job1.use_internal_scorer, False)
    tc.assertEqual(job1.internal_scorer_handicap_compensation, 'full')
    tc.assertEqual(job1.game_data, ('0', 0))
    tc.assertIsNone(job1.sgf_filename)
    tc.assertIsNone(job1.sgf_dirname)
    tc.assertIsNone(job1.void_sgf_dirname)
    tc.assertEqual(job1.sgf_event, 'testcomp')
    tc.assertIsNone(job1.gtp_log_pathname)

    job2 = fx.comp.get_game()
    tc.assertIsInstance(job2, Game_job)
    tc.assertEqual(job2.game_id, '0_1')
    tc.assertEqual(job2.player_b.code, 't2')
    tc.assertEqual(job2.player_w.code, 't1')

    result1 = Game_result.from_score('b', 8.5)
    result1.set_players({'b' : 't1', 'w' : 't2'})
    response1 = Game_job_result()
    response1.game_id = job1.game_id
    response1.game_result = result1
    response1.engine_descriptions = {
        't1' : Engine_description("t1 engine", "v1.2.3", None),
        't2' : Engine_description("t1 engine", None,
                                  't2 engine\ntest \xc2\xa3description'),
        }
    response1.game_data = job1.game_data
    fx.comp.process_game_result(response1)

    expected_report = dedent("""\
    t1 v t2 (1 games)
    board size: 13   komi: 7.5
         wins
    t1      1 100.00%   (black)
    t2      0   0.00%   (white)
    """)
    expected_players = dedent("""\
    player t1: t1 engine:v1.2.3
    player t2: t2 engine
    test \xc2\xa3description
    """)
    fx.check_screen_report(expected_report)
    fx.check_short_report(expected_report, expected_players)

    tc.assertListEqual(
        fx.comp.get_tournament_results().get_matchup_results('0'), [result1])
コード例 #3
0
ファイル: cem_tuner_tests.py プロジェクト: uduse/gomill
def test_random_candidate_colour(tc):
    comp = cem_tuners.Cem_tuner('cemtest')
    config = default_config()
    config['candidate_colour'] = 'random'
    random.seed(1002)
    comp.initialise_from_control_file(config)
    comp.set_clean_status()

    job1 = comp.get_game()
    tc.assertIsInstance(job1, Game_job)
    tc.assertEqual(job1.player_b.code, 'g0#0')
    tc.assertEqual(job1.player_w.code, 'opp')

    job2 = comp.get_game()
    tc.assertIsInstance(job2, Game_job)
    tc.assertEqual(job2.player_b.code, 'g0#1')
    tc.assertEqual(job2.player_w.code, 'opp')

    result1 = Game_result.from_score('b', 8.5)
    result1.set_players({'b': 'g0#0', 'w': 'opp'})
    response1 = Game_job_result()
    response1.game_id = job1.game_id
    response1.game_result = result1
    response1.engine_descriptions = {
        'opp': Engine_description("opp engine", "v1.2.3", None),
        '#0': Engine_description("candidate engine", None, None),
    }
    response1.game_data = job1.game_data
    comp.process_game_result(response1)

    tc.assertEqual(comp.wins, [1, 0, 0, 0])
コード例 #4
0
def test_random_candidate_colour(tc):
    comp = mcts_tuners.Mcts_tuner('mctstest')
    config = default_config()
    config['candidate_colour'] = 'random'
    random.seed(1001)
    comp.initialise_from_control_file(config)
    comp.set_clean_status()
    tree = comp.tree

    job1 = comp.get_game()
    tc.assertIsInstance(job1, Game_job)
    tc.assertEqual(job1.player_b.code, '#0')
    tc.assertEqual(job1.player_w.code, 'opp')

    job2 = comp.get_game()
    tc.assertIsInstance(job2, Game_job)
    tc.assertEqual(job2.player_b.code, 'opp')
    tc.assertEqual(job2.player_w.code, '#1')

    result1 = Game_result.from_score('b', 7.5)
    result1.set_players({'b' : '#0', 'w' : 'opp'})
    response1 = Game_job_result()
    response1.game_id = job1.game_id
    response1.game_result = result1
    response1.engine_descriptions = {
        'opp' : Engine_description("opp engine", None, None),
        '#0'  : Engine_description("candidate engine", None, None),
        }
    response1.game_data = job1.game_data
    comp.process_game_result(response1)

    tc.assertEqual(tree.root.visits, 11)
    tc.assertEqual(tree.root.wins, 6)
コード例 #5
0
def test_play(tc):
    fx = Playoff_fixture(tc)
    tc.assertIsNone(fx.comp.description)

    job1 = fx.comp.get_game()
    tc.assertIsInstance(job1, Game_job)
    tc.assertEqual(job1.game_id, '0_0')
    tc.assertEqual(job1.player_b.code, 't1')
    tc.assertEqual(job1.player_w.code, 't2')
    tc.assertEqual(job1.board_size, 13)
    tc.assertEqual(job1.komi, 7.5)
    tc.assertEqual(job1.move_limit, 1000)
    tc.assertIs(job1.use_internal_scorer, False)
    tc.assertEqual(job1.internal_scorer_handicap_compensation, 'full')
    tc.assertEqual(job1.game_data, ('0', 0))
    tc.assertIsNone(job1.sgf_filename)
    tc.assertIsNone(job1.sgf_dirname)
    tc.assertIsNone(job1.void_sgf_dirname)
    tc.assertEqual(job1.sgf_event, 'testcomp')
    tc.assertIsNone(job1.gtp_log_pathname)

    job2 = fx.comp.get_game()
    tc.assertIsInstance(job2, Game_job)
    tc.assertEqual(job2.game_id, '0_1')
    tc.assertEqual(job2.player_b.code, 't2')
    tc.assertEqual(job2.player_w.code, 't1')

    result1 = Game_result.from_score('b', 8.5)
    result1.set_players({'b': 't1', 'w': 't2'})
    response1 = Game_job_result()
    response1.game_id = job1.game_id
    response1.game_result = result1
    response1.engine_descriptions = {
        't1':
        Engine_description("t1 engine", "v1.2.3", None),
        't2':
        Engine_description("t1 engine", None,
                           't2 engine\ntest \xc2\xa3description'),
    }
    response1.game_data = job1.game_data
    fx.comp.process_game_result(response1)

    expected_report = dedent("""\
    t1 v t2 (1 games)
    board size: 13   komi: 7.5
         wins
    t1      1 100.00%   (black)
    t2      0   0.00%   (white)
    """)
    expected_players = dedent("""\
    player t1: t1 engine:v1.2.3
    player t2: t2 engine
    test \xc2\xa3description
    """)
    fx.check_screen_report(expected_report)
    fx.check_short_report(expected_report, expected_players)

    tc.assertListEqual(
        fx.comp.get_tournament_results().get_matchup_results('0'), [result1])
コード例 #6
0
ファイル: cem_tuner_tests.py プロジェクト: pnprog/gomill
def test_play(tc):
    comp = cem_tuners.Cem_tuner('cemtest')
    comp.initialise_from_control_file(default_config())
    comp.set_clean_status()

    tc.assertEqual(comp.generation, 0)
    tc.assertEqual(comp.distribution.format(),
                   " 0.50~1.00 50.00~1000.00")

    job1 = comp.get_game()
    tc.assertIsInstance(job1, Game_job)
    tc.assertEqual(job1.game_id, 'g0#0r0')
    tc.assertEqual(job1.player_b.code, 'g0#0')
    tc.assertEqual(job1.player_w.code, 'opp')
    tc.assertEqual(job1.board_size, 13)
    tc.assertEqual(job1.komi, 7.5)
    tc.assertEqual(job1.move_limit, 1000)
    tc.assertIs(job1.use_internal_scorer, False)
    tc.assertEqual(job1.internal_scorer_handicap_compensation, 'full')
    tc.assertEqual(job1.game_data, (0, 'g0#0', 0))
    tc.assertEqual(job1.sgf_event, 'cemtest')
    tc.assertRegexpMatches(job1.sgf_note, '^Candidate parameters: axa ')

    job2 = comp.get_game()
    tc.assertIsInstance(job2, Game_job)
    tc.assertEqual(job2.game_id, 'g0#1r0')
    tc.assertEqual(job2.player_b.code, 'g0#1')
    tc.assertEqual(job2.player_w.code, 'opp')

    tc.assertEqual(comp.wins, [0, 0, 0, 0])

    result1 = Game_result.from_score('b', 8.5)
    result1.set_players({'b' : 'g0#0', 'w' : 'opp'})
    response1 = Game_job_result()
    response1.game_id = job1.game_id
    response1.game_result = result1
    response1.engine_descriptions = {
        'opp' : Engine_description("opp engine", "v1.2.3", None),
        '#0'  : Engine_description("candidate engine", None,
                                   'candidate engine description'),
        }
    response1.game_data = job1.game_data
    comp.process_game_result(response1)

    tc.assertEqual(comp.wins, [1, 0, 0, 0])

    comp2 = cem_tuners.Cem_tuner('cemtest')
    comp2.initialise_from_control_file(default_config())
    status = pickle.loads(pickle.dumps(comp.get_status()))
    comp2.set_status(status)
    tc.assertEqual(comp2.wins, [1, 0, 0, 0])

    result2 = Game_result.from_score(None, 0)
    result2.set_players({'b' : 'g0#1', 'w' : 'opp'})
    response2 = Game_job_result()
    response2.game_id = job2.game_id
    response2.game_result = result2
    response2.engine_descriptions = response1.engine_descriptions
    response2.game_data = job2.game_data
    comp.process_game_result(response2)

    tc.assertEqual(comp.wins, [1, 0.5, 0, 0])
コード例 #7
0
ファイル: cem_tuner_tests.py プロジェクト: cjlarose/gomill
def test_play(tc):
    comp = cem_tuners.Cem_tuner('cemtest')
    comp.initialise_from_control_file(default_config())
    comp.set_clean_status()

    tc.assertEqual(comp.generation, 0)
    tc.assertEqual(comp.distribution.format(),
                   " 0.50~1.00 50.00~1000.00")

    job1 = comp.get_game()
    tc.assertIsInstance(job1, Game_job)
    tc.assertEqual(job1.game_id, 'g0#0r0')
    tc.assertEqual(job1.player_b.code, 'g0#0')
    tc.assertEqual(job1.player_w.code, 'opp')
    tc.assertEqual(job1.board_size, 13)
    tc.assertEqual(job1.komi, 7.5)
    tc.assertEqual(job1.move_limit, 1000)
    tc.assertIs(job1.use_internal_scorer, False)
    tc.assertEqual(job1.internal_scorer_handicap_compensation, 'full')
    tc.assertEqual(job1.game_data, (0, 'g0#0', 0))
    tc.assertEqual(job1.sgf_event, 'cemtest')
    tc.assertRegexpMatches(job1.sgf_note, '^Candidate parameters: axa ')

    job2 = comp.get_game()
    tc.assertIsInstance(job2, Game_job)
    tc.assertEqual(job2.game_id, 'g0#1r0')
    tc.assertEqual(job2.player_b.code, 'g0#1')
    tc.assertEqual(job2.player_w.code, 'opp')

    tc.assertEqual(comp.wins, [0, 0, 0, 0])

    result1 = Game_result.from_score('b', 8.5)
    result1.set_players({'b' : 'g0#0', 'w' : 'opp'})
    response1 = Game_job_result()
    response1.game_id = job1.game_id
    response1.game_result = result1
    response1.engine_descriptions = {
        'opp' : Engine_description("opp engine", "v1.2.3", None),
        '#0'  : Engine_description("candidate engine", None,
                                   'candidate engine description'),
        }
    response1.game_data = job1.game_data
    comp.process_game_result(response1)

    tc.assertEqual(comp.wins, [1, 0, 0, 0])

    comp2 = cem_tuners.Cem_tuner('cemtest')
    comp2.initialise_from_control_file(default_config())
    status = pickle.loads(pickle.dumps(comp.get_status()))
    comp2.set_status(status)
    tc.assertEqual(comp2.wins, [1, 0, 0, 0])

    result2 = Game_result.from_score(None, 0)
    result2.set_players({'b' : 'g0#1', 'w' : 'opp'})
    response2 = Game_job_result()
    response2.game_id = job2.game_id
    response2.game_result = result2
    response2.engine_descriptions = response1.engine_descriptions
    response2.game_data = job2.game_data
    comp.process_game_result(response2)

    tc.assertEqual(comp.wins, [1, 0.5, 0, 0])
コード例 #8
0
def test_play(tc):
    comp = mcts_tuners.Mcts_tuner('mctstest')
    comp.initialise_from_control_file(default_config())
    comp.set_clean_status()
    tree = comp.tree
    tc.assertEqual(comp.outstanding_simulations, {})

    tc.assertEqual(tree.root.visits, 10)
    tc.assertEqual(tree.root.wins, 5)
    tc.assertEqual(sum(node.visits - 10 for node in tree.root.children), 0)
    tc.assertEqual(sum(node.wins - 5 for node in tree.root.children), 0)

    job1 = comp.get_game()
    tc.assertIsInstance(job1, Game_job)
    tc.assertEqual(job1.game_id, '0')
    tc.assertEqual(job1.player_b.code, 'opp')
    tc.assertEqual(job1.player_w.code, '#0')
    tc.assertEqual(job1.board_size, 13)
    tc.assertEqual(job1.komi, 7.5)
    tc.assertEqual(job1.move_limit, 1000)
    tc.assertIs(job1.use_internal_scorer, False)
    tc.assertEqual(job1.internal_scorer_handicap_compensation, 'full')
    tc.assertEqual(job1.game_data, 0)
    tc.assertEqual(job1.sgf_event, 'mctstest')
    tc.assertRegexpMatches(job1.sgf_note, '^Candidate parameters: rsn@ ')
    tc.assertItemsEqual(comp.outstanding_simulations.keys(), [0])

    job2 = comp.get_game()
    tc.assertIsInstance(job2, Game_job)
    tc.assertEqual(job2.game_id, '1')
    tc.assertEqual(job2.player_b.code, 'opp')
    tc.assertEqual(job2.player_w.code, '#1')
    tc.assertItemsEqual(comp.outstanding_simulations.keys(), [0, 1])

    result1 = Game_result.from_score('w', 8.5)
    result1.set_players({'b': 'opp', 'w': '#1'})
    response1 = Game_job_result()
    response1.game_id = job1.game_id
    response1.game_result = result1

    response1.engine_descriptions = {
        'opp':
        Engine_description("opp engine", "v1.2.3", None),
        '#0':
        Engine_description("candidate engine", None,
                           'candidate engine description'),
    }
    response1.game_data = job1.game_data
    comp.process_game_result(response1)
    tc.assertItemsEqual(comp.outstanding_simulations.keys(), [1])

    tc.assertEqual(tree.root.visits, 11)
    tc.assertEqual(tree.root.wins, 6)
    tc.assertEqual(sum(node.visits - 10 for node in tree.root.children), 1)
    tc.assertEqual(sum(node.wins - 5 for node in tree.root.children), 1)
    tc.assertRegexpMatches(competition_test_support.get_short_report(comp),
                           r"(?m)^opponent \(opp\): opp engine:v1.2.3$")

    comp2 = mcts_tuners.Mcts_tuner('mctstest')
    comp2.initialise_from_control_file(default_config())
    status = pickle.loads(pickle.dumps(comp.get_status()))
    comp2.set_status(status)
    tc.assertEqual(comp2.tree.root.visits, 11)
    tc.assertEqual(comp2.tree.root.wins, 6)
    tc.assertEqual(sum(node.visits - 10 for node in comp2.tree.root.children),
                   1)
    tc.assertEqual(sum(node.wins - 5 for node in comp2.tree.root.children), 1)

    config3 = default_config()
    # changed split
    config3['parameters'][0] = Parameter_config('resign_at',
                                                scale=float,
                                                split=11,
                                                format="rsn@ %.2f")
    comp3 = mcts_tuners.Mcts_tuner('mctstest')
    comp3.initialise_from_control_file(config3)
    status = pickle.loads(pickle.dumps(comp.get_status()))
    with tc.assertRaises(CompetitionError) as ar:
        comp3.set_status(status)
    tc.assertEqual(str(ar.exception),
                   "status file is inconsistent with control file")

    config4 = default_config()
    # changed upper bound
    config4['parameters'][1] = Parameter_config('initial_wins',
                                                scale=mcts_tuners.LINEAR(
                                                    0, 200),
                                                split=10,
                                                format="iwins %d")
    comp4 = mcts_tuners.Mcts_tuner('mctstest')
    comp4.initialise_from_control_file(config4)
    status = pickle.loads(pickle.dumps(comp.get_status()))
    with tc.assertRaises(CompetitionError) as ar:
        comp4.set_status(status)
    tc.assertEqual(str(ar.exception),
                   "status file is inconsistent with control file")
コード例 #9
0
ファイル: mcts_tuner_tests.py プロジェクト: annabunches/pygo
def test_play(tc):
    comp = mcts_tuners.Mcts_tuner('mctstest')
    comp.initialise_from_control_file(default_config())
    comp.set_clean_status()
    tree = comp.tree
    tc.assertEqual(comp.outstanding_simulations, {})

    tc.assertEqual(tree.root.visits, 10)
    tc.assertEqual(tree.root.wins, 5)
    tc.assertEqual(sum(node.visits-10 for node in tree.root.children), 0)
    tc.assertEqual(sum(node.wins-5 for node in tree.root.children), 0)

    job1 = comp.get_game()
    tc.assertIsInstance(job1, Game_job)
    tc.assertEqual(job1.game_id, '0')
    tc.assertEqual(job1.player_b.code, 'opp')
    tc.assertEqual(job1.player_w.code, '#0')
    tc.assertEqual(job1.board_size, 13)
    tc.assertEqual(job1.komi, 7.5)
    tc.assertEqual(job1.move_limit, 1000)
    tc.assertIs(job1.use_internal_scorer, False)
    tc.assertEqual(job1.internal_scorer_handicap_compensation, 'full')
    tc.assertEqual(job1.game_data, 0)
    tc.assertEqual(job1.sgf_event, 'mctstest')
    tc.assertRegexpMatches(job1.sgf_note, '^Candidate parameters: rsn@ ')
    tc.assertItemsEqual(comp.outstanding_simulations.keys(), [0])

    job2 = comp.get_game()
    tc.assertIsInstance(job2, Game_job)
    tc.assertEqual(job2.game_id, '1')
    tc.assertEqual(job2.player_b.code, 'opp')
    tc.assertEqual(job2.player_w.code, '#1')
    tc.assertItemsEqual(comp.outstanding_simulations.keys(), [0, 1])

    result1 = Game_result({'b' : 'opp', 'w' : '#1'}, 'w')
    result1.sgf_result = "W+8.5"
    response1 = Game_job_result()
    response1.game_id = job1.game_id
    response1.game_result = result1
    response1.engine_names = {
        'opp' : 'opp engine:v1.2.3',
        '#0'  : 'candidate engine',
        }
    response1.engine_descriptions = {
        'opp' : 'opp engine:v1.2.3',
        '#0'  : 'candidate engine description',
        }
    response1.game_data = job1.game_data
    comp.process_game_result(response1)
    tc.assertItemsEqual(comp.outstanding_simulations.keys(), [1])

    tc.assertEqual(tree.root.visits, 11)
    tc.assertEqual(tree.root.wins, 6)
    tc.assertEqual(sum(node.visits-10 for node in tree.root.children), 1)
    tc.assertEqual(sum(node.wins-5 for node in tree.root.children), 1)

    comp2 = mcts_tuners.Mcts_tuner('mctstest')
    comp2.initialise_from_control_file(default_config())
    status = pickle.loads(pickle.dumps(comp.get_status()))
    comp2.set_status(status)
    tc.assertEqual(comp2.tree.root.visits, 11)
    tc.assertEqual(comp2.tree.root.wins, 6)
    tc.assertEqual(sum(node.visits-10 for node in comp2.tree.root.children), 1)
    tc.assertEqual(sum(node.wins-5 for node in comp2.tree.root.children), 1)

    config3 = default_config()
    # changed split
    config3['parameters'][0] = Parameter_config(
        'resign_at',
        scale = float,
        split = 11,
        format = "rsn@ %.2f")
    comp3 = mcts_tuners.Mcts_tuner('mctstest')
    comp3.initialise_from_control_file(config3)
    status = pickle.loads(pickle.dumps(comp.get_status()))
    with tc.assertRaises(CompetitionError) as ar:
        comp3.set_status(status)
    tc.assertEqual(str(ar.exception),
                   "status file is inconsistent with control file")

    config4 = default_config()
    # changed upper bound
    config4['parameters'][1] = Parameter_config(
        'initial_wins',
        scale = mcts_tuners.LINEAR(0, 200),
        split = 10,
        format = "iwins %d")
    comp4 = mcts_tuners.Mcts_tuner('mctstest')
    comp4.initialise_from_control_file(config4)
    status = pickle.loads(pickle.dumps(comp.get_status()))
    with tc.assertRaises(CompetitionError) as ar:
        comp4.set_status(status)
    tc.assertEqual(str(ar.exception),
                   "status file is inconsistent with control file")