Пример #1
0
    def run_championship(self):
        """
        This method runs the grand championship match. Since this is a double
        elimination tourney, the lower bracket champion has to win 2 times in
        order to win the overall championship.

        Arguments:
            :param self: This tourney object
        """
        # Get champs
        upper = self.upper_bracket.player  # pylint: disable=no-member
        lower = self.lower_bracket.player  # pylint: disable=no-member

        print('Championship Match')
        print('{} v. {}'.format(upper.name, lower.name))
        print('Match 1')
        print('---------------------------------')
        cur_match = Match(upper, lower, self.wins_needed)
        results = cur_match.play_match()
        self.matches.append(cur_match)
        print('{} wins the match in {} games!\n'.format(
            results['winner'], results['games_played']))

        winner = upper if results['winner'] == upper.name else lower
        loser = lower if results['winner'] == upper.name else upper
        loser.losses += 1

        # If the upper lost, we need to play again
        if (loser.name == upper.name):
            print('\nMatch 2')
            print('---------------------------------')
            cur_match = Match(upper, lower, self.wins_needed)
            results = cur_match.play_match()
            self.matches.append(cur_match)
            print('{} wins the match in {} games!\n'.format(
                results['winner'], results['games_played']))

            winner = upper if results['winner'] == upper.name else lower
            loser = lower if results['winner'] == upper.name else upper
            loser.losses += 1

        # We can now crown the champion!
        print('\n\n')
        print('Grand Champion')
        print('---------------------------------')
        print('{}'.format(self.victory_screen(winner.name)))
Пример #2
0
    def run_lower_bracket(self):
        """
        This method runs through the upper bracket. This advances through each
        stage and runs all matches required. Loses are done and winners advance
        to the next stage. The winner of the lower bracket plays in the grand
        championship.

        Arguments:
            :param self: This tourney
        """
        # Lower brackets alternate between major and minor events. If
        # applicable, we will do the minor for the stage (Stage 1 has
        # no minor), then we will do the majors
        stage_num = 1
        while (stage_num <= self.stages):
            print('Lower Stage {}'.format(stage_num))
            print('---------------------------\n')
            # If we are stage one, there is no minor
            if (stage_num is not 1):
                # Find the parents of all children nodes that need played
                nodes = findall(self.lower_bracket,
                                filter_=lambda node: node.name ==
                                'Stage{}-Major-Sub'.format(stage_num))
                num_match = 1
                for node in nodes:
                    print(node)
                    player1, player2 = (x.player for x in node.children)
                    cur_match = Match(player1, player2, self.wins_needed)

                    print('Match {} - {} v. {}'.format(num_match, player1.name,
                                                       player2.name))
                    print('---------------------------------')
                    results = cur_match.play_match()
                    self.matches.append(cur_match)
                    print('{} wins the match in {} games!\n'.format(
                        results['winner'], results['games_played']))

                    # Resolve Match
                    node.contestant = results['winner']
                    node.player = player1 if results[
                        'winner'] == player1.name else player2

                    # The loser is done! No more advancement. Move on to the minors.
                    loser = player2 if results[
                        'winner'] == player1.name else player1
                    loser.losses += 1

            # Now do the major
            # Find the parents of all children nodes that need played
            nodes = findall(self.lower_bracket,
                            filter_=lambda node: node.name in
                            ('Stage{}-Major'.format(stage_num)))
            num_match = 1
            for node in nodes:
                player1, player2 = (x.player for x in node.children)
                cur_match = Match(player1, player2, self.wins_needed)

                print('Match {} - {} v. {}'.format(num_match, player1.name,
                                                   player2.name))
                print('---------------------------------')
                results = cur_match.play_match()
                self.matches.append(cur_match)
                print('{} wins the match in {} games!\n'.format(
                    results['winner'], results['games_played']))

                # Resolve Match
                node.contestant = results['winner']
                node.player = player1 if results[
                    'winner'] == player1.name else player2

                # The loser is done! No more advancement. Move on to the minors.
                loser = player2 if results[
                    'winner'] == player1.name else player1
                loser.losses += 1

            # At the end of the stage, print the bracket
            stage_num += 1
            self.print_lower_bracket()

        # Done! Print the bracket
        print('End of Lower Bracket')
        print('---------------------------\n')
        self.print_brackets()
Пример #3
0
    def run_upper_bracket(self):
        """
        This method runs through the upper bracket. This advances through each
        stage and runs all matches required. Loses are demoted to the lower
        bracket and winners continue to the next stage.

        Arguments:
            :param self: This tourney
        """
        # Run through each stage and advance the winner as needed
        stage_num = 1
        while (stage_num <= self.stages):
            print('Upper Stage {}'.format(stage_num))
            print('---------------------------\n')
            cur_stage = stage_num + 1
            # Find the parents of all children nodes that need played
            nodes = findall(self.upper_bracket,
                            filter_=lambda node: node.name in
                            ('Stage{}'.format(cur_stage)))
            num_match = 1
            for node in nodes:
                player1, player2 = (x.player for x in node.children)
                cur_match = Match(player1, player2, self.wins_needed)

                print('Match {} - {} v. {}'.format(num_match, player1.name,
                                                   player2.name))
                print('---------------------------------')
                results = cur_match.play_match()
                self.matches.append(cur_match)
                print('{} wins the match in {} games!\n'.format(
                    results['winner'], results['games_played']))

                node.contestant = results['winner']
                node.player = player1 if results[
                    'winner'] == player1.name else player2

                # Move the loser down to the loser's bracket
                loser = player2 if results[
                    'winner'] == player1.name else player1
                loser.losses += 1

                # First check to see if this is the last stage
                #if(stage_num is self.stages):
                # Since we are the last stage, we go to the minor of the previous stage
                #lower = findall(self.lower_bracket, lambda node: node.name == 'Stage{}-Minor'.format(stage_num) and node.player is None)[0]
                #lower.contestant = loser.name
                #lower.player = loser
                # If we are an odd stage, we move to the major loser branch, else the minor
                #elif(stage_num % 2 is 1):
                #lower = findall(self.lower_bracket, lambda node: node.name == 'Stage{}-Major-Sub'.format(stage_num) and node.player is None)[0]
                #lower.contestant = loser.name
                #lower.player = loser
                #else:
                #lower = findall(self.lower_bracket, lambda node: node.name == 'Stage{}-Minor'.format(stage_num) and node.player is None)[0]
                #lower.contestant = loser.name
                #lower.player = loser

                if (stage_num is 1):
                    # Since we are the last stage, we go to the minor of the previous stage
                    lower = findall(
                        self.lower_bracket,
                        lambda node: node.name == 'Stage{}-Major-Sub'.format(
                            stage_num) and node.player is None)[0]
                    lower.contestant = loser.name
                    lower.player = loser
                else:
                    lower = findall(
                        self.lower_bracket,
                        lambda node: node.name == 'Stage{}-Minor'.format(
                            stage_num) and node.player is None)[0]
                    lower.contestant = loser.name
                    lower.player = loser
                num_match += 1

            # Now that this stage is done, print the brackets!
            stage_num += 1
            self.print_upper_bracket()
        # Done! Print the bracket
        print('End of Upper Bracket')
        print('---------------------------\n')
        self.print_brackets()