Example #1
0
def flush_possible(full_board):
    """
    Computes whether or not a flush is possible with the cards in the board. 
    Args: 
        full_board: list of int (deuces cards). Despite its name, does not actually have to be a 5-card board (can be 3, 4, or 5 cards)
    """
    suits = [0, 0, 0, 0]
    suit_conversion = {'d': 0, 'c': 1, 'h': 2, 's': 3}
    num_conversion = {0: 'd', 1: 'c', 2: 'h', 3: 's'}
    for card in full_board:
        suits[suit_conversion[Card.int_to_str(card)[1]]] += 1

    suit_amax = argmax(suits)
    max_suits = suits[suit_amax]
    if max_suits >= 3:
        return num_conversion[suit_amax], 5 - max_suits
    else:
        return 'n', -1
Example #2
0
def read_lookup_table(hole_cards, lookup_table):
    """
    Reads the preflop lookup table preflop_EHSs.txt.
    Args: 
        hole_cards: list of int (deuces cards)
        lookup_table: read from preflop_EHSs.txt
    Return:
        tuple (float, float): EHS, EHS^2
    """
    sorted_hole = sorted(hole_cards)
    sorted_hole.reverse()
    card_strings = [Card.int_to_str(card) for card in sorted_hole]

    if card_strings[0][1] != card_strings[1][1]:
        suited = False
    else:
        suited = True
    card_strings[0] = card_strings[0][0] + 'd'
    if suited:
        card_strings[1] = card_strings[1][0] + 'd'
    else:
        card_strings[1] = card_strings[1][0] + 's'
    card_strings = tuple(card_strings)
    return lookup_table[card_strings]
Example #3
0
def all_evaluation(full_board, evaluator):
    """
    Efficient evaluation of all possible hands on a board.
    Args:
        full_board: list of int (deuces cards). Despite its name, does not actually have to be a 5-card board (can be 3, 4, or 5 cards)
        evaluator: deuces Evaluator object 
    Returns: 
        dict of deuces cards with evaluations
    """

    all_hands = {}
    fp = flush_possible(full_board)
    ranks = ['A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2']
    suits = ['s', 'c', 'd', 'h']
    equivalent_lists = []

    if fp[0] == 'n' or fp[1] == 2:
        for rank in ranks:
            this_rank = []
            for suit in suits:
                card = Card.new(rank + suit)
                if card not in full_board:
                    this_rank.append(card)
            equivalent_lists.append(this_rank)
    elif fp[1] <= 1:  #where all cards with the same rank not of the flush suit are indistinct
        altered_suits = deepcopy(suits)
        altered_suits.remove(fp[0])
        for rank in ranks:
            this_rank = []
            for suit in altered_suits:
                card = Card.new(rank + suit)
                if card not in full_board:
                    this_rank.append(card)
            equivalent_lists.append(this_rank)

            card_of_suit = Card.new(rank + fp[0])
            if card_of_suit not in full_board:
                equivalent_lists.append([card_of_suit])

    combos = combinations_with_replacement(equivalent_lists, 2)

    if fp[1] == 2:
        for combo in combos:
            for equivalent_x in combo[0]:
                for equivalent_y in combo[1]:
                    if equivalent_x != equivalent_y and (
                            Card.int_to_str(equivalent_x)[1] !=
                            Card.int_to_str(equivalent_y)[1]):
                        evaluation_most = evaluator.evaluate(
                            full_board, [equivalent_x, equivalent_y])
                        break

            for equivalent_x in combo[0]:
                for equivalent_y in combo[1]:
                    if equivalent_x != equivalent_y and (
                            Card.int_to_str(equivalent_x)[1] !=
                            Card.int_to_str(equivalent_y)[1]):
                        all_hands[tuple(sorted([equivalent_x, equivalent_y
                                                ]))] = evaluation_most
                    elif equivalent_x != equivalent_y and (
                            Card.int_to_str(equivalent_x)[1]
                            == Card.int_to_str(equivalent_y)[1]):
                        special_evaluation = evaluator.evaluate(
                            full_board, [equivalent_x, equivalent_y])
                        all_hands[tuple(sorted([equivalent_x, equivalent_y
                                                ]))] = special_evaluation

    else:
        for combo in combos:
            for equivalent_x in combo[0]:
                for equivalent_y in combo[1]:
                    if equivalent_x != equivalent_y:
                        evaluation = evaluator.evaluate(
                            full_board, [equivalent_x, equivalent_y])
                        break
            for equivalent_x in combo[0]:
                for equivalent_y in combo[1]:
                    if equivalent_x != equivalent_y:
                        all_hands[tuple(sorted([equivalent_x,
                                                equivalent_y]))] = evaluation

    return all_hands