Python get winner

22 Python code examples are found related to " get winner". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: game.py    From ffai with Apache License 2.0 6 votes vote down vote up
def get_winner(self):
        """
        returns the winning agent of the game. None if it's a draw.
        If the game timed out the current player loses.
        A disqualified player will lose.
        If the game is over, the team with most TDs win.
        """
        # If game timed out the current player lost
        if self.home_agent == self.actor:
            return self.away_agent
        elif self.away_agent == self.actor:
            return self.home_agent
        
        # If the game is over the player with most TDs wins
        if self.state.game_over:
            return self.get_team_agent(self.get_winning_team())
        
        return None 
Example 2
Source File: countBot.py    From IRCBots with MIT License 6 votes vote down vote up
def getWinnerChart(self):
        maxlen = 0
        for user in range(len(self.nameList)):
            if (len(self.nameList[user].username) > maxlen):
                maxlen = len(self.nameList[user].username)
        winnerString = ''
        maxWins = self.nameList[0].timesWon
        firstLoop = True
        for user in range(len(self.nameList)):
            if (self.nameList[user].timesWon > 0):
                if (not firstLoop):
                    winnerString += '\n'
                winnerString += self.nameList[user].username + ":"
                remlen = maxlen - len(self.nameList[user].username)
                for i in range(remlen + 1):
                    winnerString += " "
                for i in range(self.nameList[user].timesWon):
                    winnerString += '#'
                for i in range(maxWins - self.nameList[user].timesWon):
                    winnerString += '|'
                firstLoop = False
        return winnerString 
Example 3
Source File: game.py    From reconchess with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_winner_color(self) -> Optional[Color]:
        if not self.is_over():
            return None

        if self._resignee is not None:
            return not self._resignee

        if self.seconds_left_by_color[chess.WHITE] <= 0:
            return chess.BLACK
        elif self.seconds_left_by_color[chess.BLACK] <= 0:
            return chess.WHITE

        if self.board.king(chess.WHITE) is None:
            return chess.BLACK
        elif self.board.king(chess.BLACK) is None:
            return chess.WHITE

        return None 
Example 4
Source File: go.py    From AlphaGOZero-python-tensorflow with MIT License 6 votes vote down vote up
def get_winner(self):
        """Calculate score of board state and return player ID (1, -1, or 0 for tie)
        corresponding to winner. Uses 'Area scoring'.
        """
        # Count number of positions filled by each player, plus 1 for each eye-ish space owned
        score_white = np.sum(self.board == WHITE)
        score_black = np.sum(self.board == BLACK)
        empties = zip(*np.where(self.board == EMPTY))
        for empty in empties:
            # Check that all surrounding points are of one color
            if self.is_eyeish(empty, BLACK):
                score_black += 1
            elif self.is_eyeish(empty, WHITE):
                score_white += 1
        score_white += self.komi
        score_white -= self.passes_white
        score_black -= self.passes_black
        if score_black > score_white:
            winner = BLACK
        elif score_white > score_black:
            winner = WHITE
        else:
            # Tie
            winner = 0
        return winner 
Example 5
Source File: internal.py    From alphazero with Apache License 2.0 6 votes vote down vote up
def get_winner(board):
    for c in LIST4:
        v0 = board[c[0][0]][c[0][1]]
        if v0 == 0: continue
        v1 = board[c[1][0]][c[1][1]]
        if v0 != v1: continue
        v2 = board[c[2][0]][c[2][1]]
        if v0 != v2: continue
        v3 = board[c[3][0]][c[3][1]]
        if v0 != v3: continue
        return v0
    for y in range(BOARD_SIZE_H):
        for x in range(BOARD_SIZE_W):
            if board[y][x] == 0:
                return None
    return 0 
Example 6
Source File: view.py    From ray with Apache License 2.0 6 votes vote down vote up
def get_winner(trials):
    """Get winner trial of a job."""
    winner = {}
    # TODO: sort_key should be customized here
    sort_key = "accuracy"
    if trials and len(trials) > 0:
        first_metrics = get_trial_info(trials[0])["metrics"]
        if first_metrics and not first_metrics.get("accuracy", None):
            sort_key = "episode_reward"
        max_metric = float("-Inf")
        for t in trials:
            metrics = get_trial_info(t).get("metrics", None)
            if metrics and metrics.get(sort_key, None):
                current_metric = float(metrics[sort_key])
                if current_metric > max_metric:
                    winner["trial_id"] = t.trial_id
                    winner["metric"] = sort_key + ": " + str(current_metric)
                    max_metric = current_metric
    return winner 
Example 7
Source File: som.py    From pyclustering with GNU General Public License v3.0 6 votes vote down vote up
def get_winner_number(self):
        """!
        @brief Calculates number of winner at the last step of learning process.
        
        @return (uint) Number of winner.
        
        """

        if self.__ccore_som_pointer is not None:
            self._award = wrapper.som_get_awards(self.__ccore_som_pointer)

        winner_number = 0
        for i in range(self._size):
            if self._award[i] > 0:
                winner_number += 1

        return winner_number 
Example 8
Source File: sgf.py    From betago with MIT License 5 votes vote down vote up
def get_winner(self):
        """Return the colour of the winning player.

        Returns None if there is no RE property, or if neither player won.

        """
        try:
            colour = self.root.get(b"RE").decode(self.presenter.encoding)[0].lower()
        except LookupError:
            return None
        if colour not in ("b", "w"):
            return None
        return colour 
Example 9
Source File: models.py    From get5-web with GNU General Public License v3.0 5 votes vote down vote up
def get_winner(self):
        if self.team1_score > self.team2_score:
            return self.get_team1()
        elif self.team2_score > self.team1_score:
            return self.get_team2()
        else:
            return None 
Example 10
Source File: othello.py    From alpha_zero_othello with MIT License 5 votes vote down vote up
def get_winner(self):
        t = np.sum(self.board)
        if t > 0:
            return 1
        if t < 0:
            return -1
        return 0 
Example 11
Source File: hand_evaluator.py    From neuron_poker with MIT License 5 votes vote down vote up
def get_winner(player_hands, table_cards):
    """Determine the winning hands of multiple players"""
    player_cards_with_table_cards = []
    for player_hand in player_hands:
        player_cards_with_table_cards.append(player_hand + table_cards)

    best_hand, winner_card_type = eval_best_hand(player_cards_with_table_cards)
    best_hand_ix = (player_cards_with_table_cards.index(best_hand))
    return best_hand_ix, winner_card_type 
Example 12
Source File: rules.py    From gym with MIT License 5 votes vote down vote up
def get_round_winner(
        game: Constants.GAME,
        board: Board,
    ) -> int:
        winner = -1
        max_power = -1

        for player in board.FACE_CARDS:
            power = Rules.get_power(board.FACE_CARDS[player], game, board)
            if power > max_power:
                max_power = power
                winner = player
        return winner 
Example 13
Source File: ghost.py    From research with MIT License 5 votes vote down vote up
def get_clear_winner(latest_votes, h):
    at_height = {}
    total_vote_count = 0
    for k, v in latest_votes.items():
        anc = get_ancestor(k, h)
        at_height[anc] = at_height.get(anc, 0) + v
        if anc is not None:
            total_vote_count += v
    for k, v in at_height.items():
        if v >= total_vote_count // 2:
            return k
    return None 
Example 14
Source File: play.py    From alphagozero with MIT License 5 votes vote down vote up
def get_winner(board):
    real_board = get_real_board(board)
    points =  _get_points(real_board)
    black = points.get(1, 0) + points.get(2, 0)
    white = points.get(-1, 0) + points.get(-2, 0) + conf['KOMI']
    if black > white:
        return 1, black, white
    elif black == white:
        return 0, black, white
    else:
        return -1, black, white 
Example 15
Source File: bilibili.py    From bilibili-live-tools with MIT License 5 votes vote down vote up
def get_winner_info(self, i, g):
        url2 = 'https://api.live.bilibili.com/lottery/v1/box/getWinnerGroupInfo?aid=' + \
               str(i) + '&number=' + str(g + 1)
        response2 = await self.bili_section_get(url2, headers=self.dic_bilibili['pcheaders'])
        return response2 
Example 16
Source File: prize.py    From donation-tracker with Apache License 2.0 5 votes vote down vote up
def get_prize_winner(self):
        if self.maxwinners == 1:
            return self.get_prize_winners().first()
        else:
            raise Exception('Cannot get single winner for multi-winner prize') 
Example 17
Source File: example.py    From python with MIT License 5 votes vote down vote up
def get_winner(self):
        if self.check_player_is_winner(self.black):
            return self.black
        if self.check_player_is_winner(self.white):
            return self.white
        return self.none 
Example 18
Source File: sgf.py    From goreviewpartner with GNU General Public License v3.0 5 votes vote down vote up
def get_winner(self):
        """Return the colour of the winning player.

        Returns None if there is no RE property, or if neither player won.

        """
        try:
            colour = self.root.get("RE")[0].lower()
        except LookupError:
            return None
        if colour not in ("b", "w"):
            return None
        return colour 
Example 19
Source File: card.py    From houdini with MIT License 5 votes vote down vote up
def get_winner_seat_id(cls, first_card, second_card):
        if first_card.element != second_card.element:
            return 0 if cls.RuleSet[first_card.element] == second_card.element else 1
        elif first_card.value > second_card.value:
            return 0
        elif second_card.value > first_card.value:
            return 1
        return -1 
Example 20
Source File: card.py    From houdini with MIT License 5 votes vote down vote up
def get_round_winner(self):
        first_card, second_card = self.ninjas[0].chosen, self.ninjas[1].chosen
        self.adjust_card_values(first_card, second_card)
        self.powers = {}
        self.on_played_effects(first_card, second_card)
        self.on_scored_effects(first_card, second_card)
        winner_seat_id = self.get_winner_seat_id(first_card, second_card)
        return winner_seat_id 
Example 21
Source File: countBot.py    From IRCBots with MIT License 5 votes vote down vote up
def getWinnerString(self):
        winnerString = ''
        firstLoop = True
        for user in range(len(self.nameList)):
            if (self.nameList[user].timesWon > 0):
                if (not firstLoop):
                    winnerString += ', '
                winnerString += '[{}]: {}'.format(self.nameList[user].username,
                                                self.nameList[user].timesWon)
                firstLoop = False
        return winnerString 
Example 22
Source File: prize.py    From donation-tracker with Apache License 2.0 5 votes vote down vote up
def get_winner(self):
        prizeWinner = self.get_prize_winner()
        if prizeWinner:
            return prizeWinner.winner
        else:
            return None