Exemplo n.º 1
0
def estimate_proba(hand, board, n_player, n_simul=1000):

    hand = Card.str_to_int(hand)
    board = Card.str_to_int(board)

    evaluator = Evaluator()
    to_draw = 5 - len(board)
    deck = set_deck(hand, board)

    winnings = []

    for _ in range(n_simul):
        deck2 = deepcopy(deck)
        shuffle(deck2.cards)
        if to_draw == 1:
            board2 = board + [deck2.draw(to_draw)]
        else:
            board2 = board + deck2.draw(to_draw)
        if n_player > 2:
            other_hands = list(
                zip(deck2.draw(n_player - 1), deck2.draw(n_player - 1)))
            score_others = min([
                evaluator.evaluate(list(hand2), board2)
                for hand2 in other_hands
            ])
        elif n_player == 2:
            other_hand = deck2.draw(2)
            score_others = evaluator.evaluate(other_hand, board2)

        score_player = evaluator.evaluate(hand, board2)

        winnings += [score_player < score_others]

    return mean(winnings)
Exemplo n.º 2
0
    def __rank_players(self):

        # we first compute the strength of each player's hand
        # warning: the evaluator gives value 0 to the best possible hand
        evaluator = Evaluator()
        hand_strength = np.array([
            evaluator.evaluate(Card.str_to_int(player.hand),
                               Card.str_to_int(self.community_cards))
            if player.round_status != 'out' else np.inf
            for player in self.players
        ])

        # we then rank them, making sure equal players have equal ranks
        player_ranking = np.zeros(self.n_players)
        for rank, hand_value in enumerate(np.unique(np.sort(hand_strength))):
            player_ranking[hand_strength == hand_value] = rank

        return player_ranking
Exemplo n.º 3
0
    def GetFullDeck():
        if Deck._FULL_DECK:
            return list(Deck._FULL_DECK)

        # create the standard 52 card deck
        for rank in Card.STR_RANKS:
            for suit, val in Card.CHAR_SUIT_TO_INT_SUIT.items():
                Deck._FULL_DECK.append(Card.str_to_int(rank + suit))

        return list(Deck._FULL_DECK)