Exemplo n.º 1
0
def test_jigo_reporting(tc):
    fx = Playoff_fixture(tc)

    def winner(i):
        if i in (0, 3):
            return 'b'
        elif i in (2, 4):
            return 'w'
        else:
            return None
    jobs = [fx.comp.get_game() for _ in range(8)]
    for i in range(6):
        response = fake_response(jobs[i], winner(i))
        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%       2 66.67%     1  33.33%
    t2      4 66.67%       2 66.67%     3 100.00%
                           3 50.00%     3  50.00%
    """))

    response = fake_response(jobs[6], None)
    fx.comp.process_game_result(response)
    fx.check_screen_report(dedent("""\
    t1 v t2 (7 games)
    board size: 13   komi: 7.5
         wins              black          white
    t1    2.5 35.71%       2.5 62.50%     1.5 50.00%
    t2    4.5 64.29%       2.5 83.33%     3.5 87.50%
                           3.5 50.00%     3.5 50.00%
    """))
Exemplo n.º 2
0
def test_play_many(tc):
    config = default_config()
    config['rounds'] = 30
    fx = Allplayall_fixture(tc, config)

    jobs = [fx.comp.get_game() for _ in xrange(57)]
    for i in xrange(57):
        response = fake_response(jobs[i], 'b')
        fx.comp.process_game_result(response)

    fx.check_screen_report(dedent("""\
    57/90 games played

          A    B    C
    A t1      10-9 10-9
    B t2 9-10      10-9
    C t3 9-10 9-10
    """))

    tc.assertEqual(
        len(fx.comp.get_tournament_results().get_matchup_results('AvB')), 19)

    comp2 = competition_test_support.check_round_trip(tc, fx.comp, config)
    jobs2 = [comp2.get_game() for _ in range(4)]
    tc.assertListEqual([job.game_id for job in jobs2],
                       ['AvB_19', 'AvC_19', 'BvC_19', 'AvB_20'])
    tr = comp2.get_tournament_results()
    tc.assertEqual(len(tr.get_matchup_results('AvB')), 19)
    ms = tr.get_matchup_stats('AvB')
    tc.assertEqual(ms.total, 19)
    tc.assertEqual(ms.wins_1, 10)
    tc.assertIs(ms.alternating, True)
Exemplo n.º 3
0
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")
Exemplo n.º 4
0
def test_self_play(tc):
    config = default_config()
    config['matchups'] = [
        Matchup_config('t1', 't1', alternating=True),
        Matchup_config('t1', 't1', alternating=False),
        ]
    fx = Playoff_fixture(tc, config)

    jobs = [fx.comp.get_game() for _ in range(20)]
    for i, job in enumerate(jobs):
        response = fake_response(job, 'b' if i < 9 else 'w')
        fx.comp.process_game_result(response)
    fx.check_screen_report(dedent("""\
    t1 v t1#2 (10 games)
    board size: 13   komi: 7.5
           wins              black        white
    t1        6 60.00%       3 60.00%     3 60.00%
    t1#2      4 40.00%       2 40.00%     2 40.00%
                             5 50.00%     5 50.00%

    t1 v t1#2 (10 games)
    board size: 13   komi: 7.5
           wins
    t1        4 40.00%   (black)
    t1#2      6 60.00%   (white)
    """))

    competition_test_support.check_round_trip(tc, fx.comp, config)
Exemplo n.º 5
0
def test_play_many(tc):
    config = default_config()
    config['rounds'] = 30
    fx = Allplayall_fixture(tc, config)

    jobs = [fx.comp.get_game() for _ in xrange(57)]
    for i in xrange(57):
        response = fake_response(jobs[i], 'b')
        fx.comp.process_game_result(response)

    fx.check_screen_report(
        dedent("""\
    57/90 games played

          A    B    C
    A t1      10-9 10-9
    B t2 9-10      10-9
    C t3 9-10 9-10
    """))

    tc.assertEqual(
        len(fx.comp.get_tournament_results().get_matchup_results('AvB')), 19)

    comp2 = competition_test_support.check_round_trip(tc, fx.comp, config)
    jobs2 = [comp2.get_game() for _ in range(4)]
    tc.assertListEqual([job.game_id for job in jobs2],
                       ['AvB_19', 'AvC_19', 'BvC_19', 'AvB_20'])
    tr = comp2.get_tournament_results()
    tc.assertEqual(len(tr.get_matchup_results('AvB')), 19)
    ms = tr.get_matchup_stats('AvB')
    tc.assertEqual(ms.total, 19)
    tc.assertEqual(ms.wins_1, 10)
    tc.assertIs(ms.alternating, True)
Exemplo n.º 6
0
def test_unknown_result_reporting(tc):
    fx = Playoff_fixture(tc)

    def winner(i):
        if i in (0, 3):
            return 'b'
        elif i in (2, 4):
            return 'w'
        else:
            return 'unknown'

    jobs = [fx.comp.get_game() for _ in range(8)]
    for i in range(6):
        response = fake_response(jobs[i], winner(i))
        fx.comp.process_game_result(response)
    fx.check_screen_report(
        dedent("""\
    t1 v t2 (6 games)
    unknown results: 2 33.33%
    board size: 13   komi: 7.5
         wins              black        white
    t1      1 16.67%       1 33.33%     0  0.00%
    t2      3 50.00%       1 33.33%     2 66.67%
                           2 33.33%     2 33.33%
    """))
Exemplo n.º 7
0
def test_play_many(tc):
    fx = Playoff_fixture(tc)

    jobs = [fx.comp.get_game() for _ in range(8)]
    for i in [0, 3]:
        response = fake_response(jobs[i], 'b')
        fx.comp.process_game_result(response)
    jobs += [fx.comp.get_game() for _ in range(3)]
    for i in [4, 2, 6, 7]:
        response = fake_response(jobs[i], '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%
    """))

    tc.assertEqual(
        len(fx.comp.get_tournament_results().get_matchup_results('0')), 6)

    #tc.assertEqual(fx.comp.scheduler.allocators['0'].issued, 11)
    #tc.assertEqual(fx.comp.scheduler.allocators['0'].fixed, 6)

    comp2 = competition_test_support.check_round_trip(tc, fx.comp,
                                                      default_config())

    #tc.assertEqual(comp2.scheduler.allocators['0'].issued, 6)
    #tc.assertEqual(comp2.scheduler.allocators['0'].fixed, 6)

    jobs2 = [comp2.get_game() for _ in range(4)]
    tc.assertListEqual([job.game_id for job in jobs2],
                       ['0_1', '0_5', '0_8', '0_9'])
    tr = comp2.get_tournament_results()
    tc.assertEqual(len(tr.get_matchup_results('0')), 6)
    ms = tr.get_matchup_stats('0')
    tc.assertEqual(ms.total, 6)
    tc.assertEqual(ms.wins_1, 2)
    tc.assertEqual(ms.wins_b, 2)
Exemplo n.º 8
0
def test_play_many(tc):
    fx = Playoff_fixture(tc)

    jobs = [fx.comp.get_game() for _ in range(8)]
    for i in [0, 3]:
        response = fake_response(jobs[i], 'b')
        fx.comp.process_game_result(response)
    jobs += [fx.comp.get_game() for _ in range(3)]
    for i in [4, 2, 6, 7]:
        response = fake_response(jobs[i], '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%
    """))

    tc.assertEqual(
        len(fx.comp.get_tournament_results().get_matchup_results('0')), 6)

    #tc.assertEqual(fx.comp.scheduler.allocators['0'].issued, 11)
    #tc.assertEqual(fx.comp.scheduler.allocators['0'].fixed, 6)

    comp2 = competition_test_support.check_round_trip(
        tc, fx.comp, default_config())

    #tc.assertEqual(comp2.scheduler.allocators['0'].issued, 6)
    #tc.assertEqual(comp2.scheduler.allocators['0'].fixed, 6)

    jobs2 = [comp2.get_game() for _ in range(4)]
    tc.assertListEqual([job.game_id for job in jobs2],
                       ['0_1', '0_5', '0_8', '0_9'])
    tr = comp2.get_tournament_results()
    tc.assertEqual(len(tr.get_matchup_results('0')), 6)
    ms = tr.get_matchup_stats('0')
    tc.assertEqual(ms.total, 6)
    tc.assertEqual(ms.wins_1, 2)
    tc.assertEqual(ms.wins_b, 2)
Exemplo n.º 9
0
def test_engine_with_no_name(tc):
    fx = Playoff_fixture(tc)
    job = fx.comp.get_game()
    response = fake_response(job, 'b')
    response.engine_descriptions['t2'] = Engine_description(None, None, None)
    fx.comp.process_game_result(response)
    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: [no description available]
    """)
    fx.check_short_report(expected_report, expected_players)
Exemplo n.º 10
0
def test_unknown_result_reporting(tc):
    fx = Playoff_fixture(tc)

    def winner(i):
        if i in (0, 3):
            return 'b'
        elif i in (2, 4):
            return 'w'
        else:
            return 'unknown'
    jobs = [fx.comp.get_game() for _ in range(8)]
    for i in range(6):
        response = fake_response(jobs[i], winner(i))
        fx.comp.process_game_result(response)
    fx.check_screen_report(dedent("""\
    t1 v t2 (6 games)
    unknown results: 2 33.33%
    board size: 13   komi: 7.5
         wins              black        white
    t1      1 16.67%       1 33.33%     0  0.00%
    t2      3 50.00%       1 33.33%     2 66.67%
                           2 33.33%     2 33.33%
    """))
Exemplo n.º 11
0
def test_play(tc):
    fx = Allplayall_fixture(tc)
    tc.assertIsNone(fx.comp.description)

    job1 = fx.comp.get_game()
    tc.assertIsInstance(job1, Game_job)
    tc.assertEqual(job1.game_id, 'AvB_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, ('AvB', 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, 'AvC_0')
    tc.assertEqual(job2.player_b.code, 't1')
    tc.assertEqual(job2.player_w.code, 't3')

    response1 = fake_response(job1, 'b')
    fx.comp.process_game_result(response1)
    response2 = fake_response(job2, None)
    fx.comp.process_game_result(response2)

    expected_grid = dedent("""\
    2 games played

          A       B   C
    A t1         1-0 0.5-0.5
    B t2 0-1         0-0
    C t3 0.5-0.5 0-0
    """)
    expected_matchups = dedent("""\
    t1 v t2 (1 games)
    board size: 13   komi: 7.5
         wins
    t1      1 100.00%   (black)
    t2      0   0.00%   (white)

    t1 v t3 (1 games)
    board size: 13   komi: 7.5
         wins
    t1    0.5 50.00%   (black)
    t3    0.5 50.00%   (white)
    """)
    expected_players = dedent("""\
    player t1: t1 engine:v1.2.3
    player t2: t2 engine
    testdescription
    player t3: t3 engine
    testdescription
    """)
    fx.check_screen_report(expected_grid)
    fx.check_short_report(expected_grid, expected_matchups, expected_players)

    avb_results = fx.comp.get_tournament_results().get_matchup_results('AvB')
    tc.assertEqual(avb_results, [response1.game_result])
Exemplo n.º 12
0
def test_matchup_reappearance(tc):
    # Test that if a matchup is removed and added again, we remember the game
    # number. Test that we report the 'ghost' matchup in the short report (but
    # not the screen report).
    config1 = default_config()
    config1['matchups'].append(Matchup_config('t2', 't1'))
    config2 = default_config()
    config3 = default_config()
    config3['matchups'].append(Matchup_config('t2', 't1'))

    comp1 = playoffs.Playoff('testcomp')
    comp1.initialise_from_control_file(config1)
    comp1.set_clean_status()
    jobs1 = [comp1.get_game() for _ in range(8)]
    for job in jobs1:
        comp1.process_game_result(fake_response(job, 'b'))
    tc.assertListEqual(
        [job.game_id for job in jobs1],
        ['0_0', '1_0', '0_1', '1_1', '0_2', '1_2', '0_3', '1_3'])
    expected_matchups_1 = dedent("""\
    t1 v t2 (4 games)
    board size: 13   komi: 7.5
         wins              black         white
    t1      2 50.00%       2 100.00%     0 0.00%
    t2      2 50.00%       2 100.00%     0 0.00%
                           4 100.00%     0 0.00%

    t2 v t1 (4 games)
    board size: 13   komi: 7.5
         wins
    t2      4 100.00%   (black)
    t1      0   0.00%   (white)
    """)
    check_screen_report(tc, comp1, expected_matchups_1)
    check_short_report(tc, comp1, expected_matchups_1, expected_fake_players)

    comp2 = playoffs.Playoff('testcomp')
    comp2.initialise_from_control_file(config2)
    comp2.set_status(pickle.loads(pickle.dumps(comp1.get_status())))
    jobs2 = [comp2.get_game() for _ in range(4)]
    tc.assertListEqual(
        [job.game_id for job in jobs2],
        ['0_4', '0_5', '0_6', '0_7'])
    for job in jobs2:
        comp2.process_game_result(fake_response(job, 'b'))
    expected_matchups_2 = dedent("""\
    t1 v t2 (8 games)
    board size: 13   komi: 7.5
         wins              black         white
    t1      4 50.00%       4 100.00%     0 0.00%
    t2      4 50.00%       4 100.00%     0 0.00%
                           8 100.00%     0 0.00%
    """)
    check_screen_report(tc, comp2, expected_matchups_2)
    expected_matchups_2b = dedent("""\
    t2 v t1 (4 games)
    ?? (missing from control file)
         wins
    t2      4 100.00%   (black)
    t1      0   0.00%   (white)
    """)
    check_short_report(
        tc, comp2,
        expected_matchups_2 + "\n" + expected_matchups_2b,
        expected_fake_players)

    comp3 = playoffs.Playoff('testcomp')
    comp3.initialise_from_control_file(config3)
    comp3.set_status(pickle.loads(pickle.dumps(comp2.get_status())))
    jobs3 = [comp3.get_game() for _ in range(8)]
    tc.assertListEqual(
        [job.game_id for job in jobs3],
        ['1_4', '1_5', '1_6', '1_7', '0_8', '1_8', '0_9', '1_9'])
    expected_matchups_3 = dedent("""\
    t1 v t2 (8 games)
    board size: 13   komi: 7.5
         wins              black         white
    t1      4 50.00%       4 100.00%     0 0.00%
    t2      4 50.00%       4 100.00%     0 0.00%
                           8 100.00%     0 0.00%

    t2 v t1 (4 games)
    board size: 13   komi: 7.5
         wins
    t2      4 100.00%   (black)
    t1      0   0.00%   (white)
    """)
    check_screen_report(tc, comp3, expected_matchups_3)
    check_short_report(tc, comp3, expected_matchups_3, expected_fake_players)
Exemplo n.º 13
0
def test_play(tc):
    fx = Allplayall_fixture(tc)
    tc.assertIsNone(fx.comp.description)

    job1 = fx.comp.get_game()
    tc.assertIsInstance(job1, Game_job)
    tc.assertEqual(job1.game_id, 'AvB_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, ('AvB', 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, 'AvC_0')
    tc.assertEqual(job2.player_b.code, 't1')
    tc.assertEqual(job2.player_w.code, 't3')

    response1 = fake_response(job1, 'b')
    fx.comp.process_game_result(response1)
    response2 = fake_response(job2, None)
    fx.comp.process_game_result(response2)

    expected_grid = dedent("""\
    2 games played

          A       B   C
    A t1         1-0 0.5-0.5
    B t2 0-1         0-0
    C t3 0.5-0.5 0-0
    """)
    expected_matchups = dedent("""\
    t1 v t2 (1 games)
    board size: 13   komi: 7.5
         wins
    t1      1 100.00%   (black)
    t2      0   0.00%   (white)

    t1 v t3 (1 games)
    board size: 13   komi: 7.5
         wins
    t1    0.5 50.00%   (black)
    t3    0.5 50.00%   (white)
    """)
    expected_players = dedent("""\
    player t1: t1 engine:v1.2.3
    player t2: t2 engine
    testdescription
    player t3: t3 engine
    testdescription
    """)
    fx.check_screen_report(expected_grid)
    fx.check_short_report(expected_grid, expected_matchups, expected_players)

    avb_results = fx.comp.get_tournament_results().get_matchup_results('AvB')
    tc.assertEqual(avb_results, [response1.game_result])