Exemple #1
0
    def test_tournament_winner(self):
        stdout = []

        def mock_print(str="", *args, **kwargs):
            stdout.append(str)

        c = {
            "location": None,
            "date": None,
            "bonusmatch": None,
            "teams": [
                {"id": "group0", "spec": "StoppingPlayer", "members": []},
                {"id": "group1", "spec": "SmartEatingPlayer", "members": []},
                {"id": "group2", "spec": "StoppingPlayer", "members": []},
                {"id": "group3", "spec": "StoppingPlayer", "members": []},
                {"id": "group4", "spec": "StoppingPlayer", "members": []},
            ],
            "filter": "small",
        }
        config = tournament.Config(c)
        config.print = mock_print
        config.viewer = 'null'
        config.state = None
        config.tournament_log_folder = None

        # group1 should win
        self.assertEqual("group1", tournament.start_match(config, ["group0", "group1"]))
        self.assertEqual("group1", tournament.start_match(config, ["group1", "group0"]))
        self.assertEqual(False, tournament.start_match(config, ["group0", "group0"]))

        tournament.present_teams(config)

        state = tournament.State(config)
        rr_ranking = tournament.round1(config, state)

        if config.bonusmatch:
            sorted_ranking = komode.sort_ranks(rr_ranking[:-1]) + [rr_ranking[-1]]
        else:
            sorted_ranking = komode.sort_ranks(rr_ranking)

        winner = tournament.round2(config, sorted_ranking, state)
        self.assertEqual(winner, 'group1')
Exemple #2
0
    if os.path.isfile(ARGS.state):
        if not ARGS.load_state:
            config.print("Found state file in {state_file}. Restore with --load-state. Aborting.".format(state_file=ARGS.state))
            sys.exit(-1)
        else:
            state = State.load(config, ARGS.state)
    else:
        state = State(config)

    random.seed(config.seed)

    if state.round1['played']:
        # We have already played one match. Do not speak the introduction.
        old_speak = config.speak
        config.speak = False
        tournament.present_teams(config)
        config.speak = old_speak
    else:
        tournament.present_teams(config)

    rr_ranking = tournament.round1(config, state)
    state.round2["round_robin_ranking"] = rr_ranking
    state.save(ARGS.state)

    if config.bonusmatch:
        sorted_ranking = tournament.komode.sort_ranks(rr_ranking[:-1]) + [rr_ranking[-1]]
    else:
        sorted_ranking = tournament.komode.sort_ranks(rr_ranking)

    winner = tournament.round2(config, sorted_ranking, state)
Exemple #3
0
            config.print(
                "Found state file in {state_file}. Restore with --load-state. Aborting.".format(state_file=ARGS.state)
            )
            sys.exit(-1)
        else:
            state = State.load(config, ARGS.state)
    else:
        state = State(config)

    random.seed(config.seed)

    if state.round1["played"]:
        # We have already played one match. Do not speak the introduction.
        old_speak = config.speak
        config.speak = False
        tournament.present_teams(config)
        config.speak = old_speak
    else:
        tournament.present_teams(config)

    rr_ranking = tournament.round1(config, state)
    state.round2["round_robin_ranking"] = rr_ranking
    state.save(ARGS.state)

    if config.bonusmatch:
        sorted_ranking = tournament.komode.sort_ranks(rr_ranking[:-1]) + [rr_ranking[-1]]
    else:
        sorted_ranking = tournament.komode.sort_ranks(rr_ranking)

    winner = tournament.round2(config, sorted_ranking, state)
    def test_tournament_winner(self):
        stdout = []

        def mock_print(str="", *args, **kwargs):
            stdout.append(str)

        c = {
            "location":
            None,
            "date":
            None,
            "bonusmatch":
            None,
            "teams": [
                {
                    "id": "group0",
                    "spec": "StoppingPlayer",
                    "members": []
                },
                {
                    "id": "group1",
                    "spec": "SmartEatingPlayer",
                    "members": []
                },
                {
                    "id": "group2",
                    "spec": "StoppingPlayer",
                    "members": []
                },
                {
                    "id": "group3",
                    "spec": "StoppingPlayer",
                    "members": []
                },
                {
                    "id": "group4",
                    "spec": "StoppingPlayer",
                    "members": []
                },
            ],
            "filter":
            "small",
        }
        config = tournament.Config(c)
        config.print = mock_print
        config.viewer = 'null'
        config.state = None
        config.tournament_log_folder = None

        # group1 should win
        self.assertEqual("group1",
                         tournament.start_match(config, ["group0", "group1"]))
        self.assertEqual("group1",
                         tournament.start_match(config, ["group1", "group0"]))
        self.assertEqual(False,
                         tournament.start_match(config, ["group0", "group0"]))

        tournament.present_teams(config)

        state = tournament.State(config)
        rr_ranking = tournament.round1(config, state)

        if config.bonusmatch:
            sorted_ranking = komode.sort_ranks(
                rr_ranking[:-1]) + [rr_ranking[-1]]
        else:
            sorted_ranking = komode.sort_ranks(rr_ranking)

        winner = tournament.round2(config, sorted_ranking, state)
        self.assertEqual(winner, 'group1')