def get_ev_of_call(cards, action_list):

    hand1 = cards[0]
    hand2 = cards[1]

    hand1, hand2 = hand_functions.prepare_pair(hand1, hand2)
    win_data = cnfg.MCT[(hand1, hand2)]

    player = (len(action_list) + 1) % 2  # player who took last action

    wrt, ties, junk = win_data

    lrt = 1 - wrt - ties

    if player == 1:
        wrt_temp = lrt
        lrt = wrt
        wrt = wrt_temp

    pots, amounts, money_put_in = hand_functions.calculate_pot_from_action_list(
        action_list)

    pot_at_end = pots[-1]

    pot_to_win = pot_at_end - money_put_in[player]

    ev = wrt * pot_to_win - lrt * money_put_in[player]

    return -ev
Exemplo n.º 2
0
def calculate_outcome(action_list, small_blind, player_1_hand, player_2_hand):

    Moneys = [0, 0]

    final_action = action_list[-1]

    #First player to act here refers to player #0 it is internal to computation of pots
    #and has nothing to do with player numbers.  Player 0 is simply first person to act

    final_player_to_act = (len(action_list) + 1) % 2
    other_player = (len(action_list)) % 2

    pots, amounts, money_put_in = ev_state_logic.calculate_pot_from_action_list(
        action_list)

    if final_action == 0:
        Moneys[final_player_to_act] = -money_put_in[final_player_to_act]
        Moneys[other_player] = pots[-1] - money_put_in[other_player]

        if small_blind == 0:
            return Moneys[0], Moneys[1]
        else:
            return Moneys[1], Moneys[0]

    player_1_hand, player_2_hand = hand_functions.prepare_pair(
        player_1_hand, player_2_hand)
    wrt, hvhties, junk = cnfg.MCT[(
        player_1_hand,
        player_2_hand)]  #SF_VS_SF[(player_1_hand, player_2_hand)]

    player_1_wrt = wrt
    player_2_wrt = 1 - player_1_wrt - hvhties

    player_1_lrt = 1 - player_1_wrt - hvhties
    player_2_lrt = 1 - player_2_wrt - hvhties

    pot_at_end = pots[-1]
    if small_blind == 0:
        money_put_in_player_1 = money_put_in[0]
        money_put_in_player_2 = money_put_in[1]
    else:
        money_put_in_player_1 = money_put_in[1]
        money_put_in_player_2 = money_put_in[0]

    pot_to_win_player_1 = pot_at_end - money_put_in_player_1
    pot_to_win_player_2 = pot_at_end - money_put_in_player_2

    player_1_money = player_1_wrt * pot_to_win_player_1 - player_1_lrt * money_put_in_player_1
    player_2_money = player_2_wrt * pot_to_win_player_2 - player_2_lrt * money_put_in_player_2

    return player_1_money, player_2_money
Exemplo n.º 3
0
def generate_sf_hand_vs_sf_hand_table():
    for hand1 in cnfg.SF_LIST:
        for hand2 in cnfg.SF_LIST:
            total_wrt = 0
            total_ties = 0
            count = 0
            expanded_sf_list = generate_expanded_sf_list(hand2, hand1)
            weight = len(expanded_sf_list)
            for h2 in expanded_sf_list:
                hand1, h2 = hand_functions.prepare_pair(hand1, h2)
                wrt, ties, c = look_up_hand_vs_hand(hand1, h2)
                total_wrt += wrt
                total_ties += ties
                count += 1
            cnfg.SF_VS_SF[(hand1, hand2)] = (total_wrt / count,
                                             total_ties / count, weight)
Exemplo n.º 4
0
def hand_vs_range(hand1, range_list):
    total_wrt = 0
    total_ties = 0
    total_count = 0

    for item in range_list:
        hand2, prob = item
        hand1, hand2 = hand_functions.prepare_pair(hand1, hand2)

        if not hand_functions.is_compatible(hand1, hand2):
            continue

        wrt, ties, weight = cnfg.MCT[(hand1, hand2)]  #SF_VS_SF[(hand1, hand2)]
        total_wrt += weight * prob * wrt
        total_ties += weight * prob * ties
        total_count += weight * prob

    if total_count == 0:
        print("Unknown range: ", hand1, range_list)
    return total_wrt / total_count, total_ties / total_count
Exemplo n.º 5
0
def generate_monte_carlo_table(hand_set):
    #cycle over all cards

    hand_vs_hand_dict = {}

    progress_counter = 0

    for pair in hand_set:

        progress_counter += 1

        hand1_tuple = pair[0]
        hand2_tuple = pair[1]

        hand1_tuple, hand2_tuple = hand_functions.prepare_pair(
            hand1_tuple, hand2_tuple)

        if (hand1_tuple, hand2_tuple) not in hand_vs_hand_dict:

            wrt = hand_vs_hand_monte_carlo(hand1_tuple, hand2_tuple)

            wins, ties = wrt

            count = 1

            hand_vs_hand_dict[(hand1_tuple, hand2_tuple)] = (wins, ties, count)

        else:
            value = hand_vs_hand_dict[(hand1_tuple, hand2_tuple)]
            wins, ties, count = value

            count += 1

            hand_vs_hand_dict[(hand1_tuple, hand2_tuple)] = (wins, ties, count)

        if progress_counter % 5000 == 0:
            print(progress_counter)

    return hand_vs_hand_dict