From 767b5c84a849961561885cfe293f53ae48f3909a Mon Sep 17 00:00:00 2001 From: Wataru Inariba Date: Wed, 31 Jan 2024 22:17:40 -0500 Subject: [PATCH] Fix many --- csrc/src/equity.cpp | 196 +++++++++++++++++++----------------------- csrc/src/poker_hand.h | 4 + 2 files changed, 94 insertions(+), 106 deletions(-) diff --git a/csrc/src/equity.cpp b/csrc/src/equity.cpp index 216ae72..0eaf8dd 100644 --- a/csrc/src/equity.cpp +++ b/csrc/src/equity.cpp @@ -426,22 +426,6 @@ static void compute_cfvs_showdown_2_vs_3(const Game& game, const Range& opponent const hand_t hero_index = hero_hand & ((1 << 16) - 1); const auto hero_strength = hero_hand >> 16; - if (draw_coefficient > 0) { - if (!is_below_flush && hero_strength < WEAKEST_FLUSH) { - is_below_flush = true; - opponent_sum_0_ref = std::ref(opponent_sum_0_fd); - opponent_sum_1_ref = std::ref(opponent_sum_1_fd); - opponent_sum_2_ref = std::ref(opponent_sum_2_fd); - } - - if (!is_below_straight && hero_strength < WEAKEST_STRAIGHT) { - is_below_straight = true; - opponent_sum_0_ref = std::ref(opponent_sum_0_sd); - opponent_sum_1_ref = std::ref(opponent_sum_1_sd); - opponent_sum_2_ref = std::ref(opponent_sum_2_sd); - } - } - while (true) { const auto& opponent_hand = opponent_hands_sorted[j]; const auto opponent_strength = (opponent_hand >> 16) & STRENGTH_MASK; @@ -450,6 +434,22 @@ static void compute_cfvs_showdown_2_vs_3(const Game& game, const Range& opponent break; } + if (draw_coefficient > 0) { + if (!is_below_flush && opponent_strength < WEAKEST_FLUSH) { + is_below_flush = true; + opponent_sum_0_ref = std::ref(opponent_sum_0_fd); + opponent_sum_1_ref = std::ref(opponent_sum_1_fd); + opponent_sum_2_ref = std::ref(opponent_sum_2_fd); + } + + if (!is_below_straight && opponent_strength < WEAKEST_STRAIGHT) { + is_below_straight = true; + opponent_sum_0_ref = std::ref(opponent_sum_0_sd); + opponent_sum_1_ref = std::ref(opponent_sum_1_sd); + opponent_sum_2_ref = std::ref(opponent_sum_2_sd); + } + } + const hand_t opponent_index = opponent_hand & ((1 << 16) - 1); const double prob = opponent_range.range[opponent_index]; @@ -477,24 +477,19 @@ static void compute_cfvs_showdown_2_vs_3(const Game& game, const Range& opponent opponent_sum_2[hero_index]; if (draw_coefficient > 0) { - double weight = 1; - - if (hero_strength & FLUSH_DRAW_BIT) { - sum -= (opponent_sum_0_fd + opponent_sum_0_sd - opponent_sum_1_fd[hero_cards[0]] - - opponent_sum_1_fd[hero_cards[1]] - opponent_sum_1_sd[hero_cards[0]] - - opponent_sum_1_sd[hero_cards[1]] + opponent_sum_2_fd[hero_index] + - opponent_sum_2_sd[hero_index]) * - flush_draw_weight; - weight -= flush_draw_weight; - } - - const auto num_sd = hero_strength & STRAIGHT_DRAW_MASK; - if (num_sd > 0) { - const double straight_draw_weight = weight * straight_draw_coefficient * num_sd; - sum -= (opponent_sum_0_sd - opponent_sum_1_sd[hero_cards[0]] - - opponent_sum_1_sd[hero_cards[1]] + opponent_sum_2_sd[hero_index]) * - straight_draw_weight; - // weight -= straight_draw_weight; + if (is_below_flush) { + double weight = 1 - ((hero_strength & FLUSH_DRAW_BIT) ? flush_draw_weight : 0); + sum += (opponent_sum_0_fd - opponent_sum_1_fd[hero_cards[0]] - + opponent_sum_1_fd[hero_cards[1]] - opponent_sum_1_fd[hero_cards[2]]) * + weight; + + if (is_below_straight) { + const auto num_sd = hero_strength & STRAIGHT_DRAW_MASK; + weight *= (1 - straight_draw_coefficient * num_sd); + sum += (opponent_sum_0_sd - opponent_sum_1_sd[hero_cards[0]] - + opponent_sum_1_sd[hero_cards[1]] + opponent_sum_2_sd[hero_index]) * + weight; + } } } @@ -676,20 +671,6 @@ static void compute_cfvs_showdown_3_vs_2(const Game& game, const Range& opponent const hand_t hero_index = hero_hand & ((1 << 16) - 1); const auto hero_strength = hero_hand >> 16; - if (draw_coefficient > 0) { - if (!is_below_flush && hero_strength < WEAKEST_FLUSH) { - is_below_flush = true; - opponent_sum_0_ref = std::ref(opponent_sum_0_fd); - opponent_sum_1_ref = std::ref(opponent_sum_1_fd); - } - - if (!is_below_straight && hero_strength < WEAKEST_STRAIGHT) { - is_below_straight = true; - opponent_sum_0_ref = std::ref(opponent_sum_0_sd); - opponent_sum_1_ref = std::ref(opponent_sum_1_sd); - } - } - while (true) { const auto& opponent_hand = opponent_hands_sorted[j]; const auto opponent_strength = (opponent_hand >> 16) & STRENGTH_MASK; @@ -698,6 +679,20 @@ static void compute_cfvs_showdown_3_vs_2(const Game& game, const Range& opponent break; } + if (draw_coefficient > 0) { + if (!is_below_flush && opponent_strength < WEAKEST_FLUSH) { + is_below_flush = true; + opponent_sum_0_ref = std::ref(opponent_sum_0_fd); + opponent_sum_1_ref = std::ref(opponent_sum_1_fd); + } + + if (!is_below_straight && opponent_strength < WEAKEST_STRAIGHT) { + is_below_straight = true; + opponent_sum_0_ref = std::ref(opponent_sum_0_sd); + opponent_sum_1_ref = std::ref(opponent_sum_1_sd); + } + } + const hand_t opponent_index = opponent_hand & ((1 << 16) - 1); const double prob = opponent_range.range[opponent_index]; @@ -720,24 +715,19 @@ static void compute_cfvs_showdown_3_vs_2(const Game& game, const Range& opponent opponent_sum_1[hero_cards[2]]; if (draw_coefficient > 0) { - double weight = 1; - - if (hero_strength & FLUSH_DRAW_BIT) { - sum -= (opponent_sum_0_fd + opponent_sum_0_sd - opponent_sum_1_fd[hero_cards[0]] - - opponent_sum_1_fd[hero_cards[1]] - opponent_sum_1_fd[hero_cards[2]] - - opponent_sum_1_sd[hero_cards[0]] - opponent_sum_1_sd[hero_cards[1]] - - opponent_sum_1_sd[hero_cards[2]]) * - flush_draw_weight; - weight -= flush_draw_weight; - } - - const auto num_sd = hero_strength & STRAIGHT_DRAW_MASK; - if (num_sd > 0) { - const double straight_draw_weight = weight * straight_draw_coefficient * num_sd; - sum -= (opponent_sum_0_sd - opponent_sum_1_sd[hero_cards[0]] - - opponent_sum_1_sd[hero_cards[1]] - opponent_sum_1_sd[hero_cards[2]]) * - straight_draw_weight; - // weight -= straight_draw_weight; + if (is_below_flush) { + double weight = 1 - ((hero_strength & FLUSH_DRAW_BIT) ? flush_draw_weight : 0); + sum += (opponent_sum_0_fd - opponent_sum_1_fd[hero_cards[0]] - + opponent_sum_1_fd[hero_cards[1]] - opponent_sum_1_fd[hero_cards[2]]) * + weight; + + if (is_below_straight) { + const auto num_sd = hero_strength & STRAIGHT_DRAW_MASK; + weight *= (1 - straight_draw_coefficient * num_sd); + sum += (opponent_sum_0_sd - opponent_sum_1_sd[hero_cards[0]] - + opponent_sum_1_sd[hero_cards[1]] - opponent_sum_1_sd[hero_cards[2]]) * + weight; + } } } @@ -805,7 +795,7 @@ static void compute_cfvs_showdown_3_vs_3(const Game& game, const Range& opponent if (draw_coefficient > 0) { // merge straight draws - if (hero_strength > WEAKEST_STRAIGHT && opponent_sum_0_sd > 0.0) { + if (hero_strength > WEAKEST_STRAIGHT && opponent_sum_0_sd > 0) { opponent_sum_0 += opponent_sum_0_sd; opponent_sum_0_sd = 0; for (card_t card = 0; card < MAX_DECK_SIZE; ++card) { @@ -920,22 +910,6 @@ static void compute_cfvs_showdown_3_vs_3(const Game& game, const Range& opponent const hand_t hero_index = hero_hand & ((1 << 16) - 1); const auto hero_strength = hero_hand >> 16; - if (draw_coefficient > 0) { - if (!is_below_flush && hero_strength < WEAKEST_FLUSH) { - is_below_flush = true; - opponent_sum_0_ref = std::ref(opponent_sum_0_fd); - opponent_sum_1_ref = std::ref(opponent_sum_1_fd); - opponent_sum_2_ref = std::ref(opponent_sum_2_fd); - } - - if (!is_below_straight && hero_strength < WEAKEST_STRAIGHT) { - is_below_straight = true; - opponent_sum_0_ref = std::ref(opponent_sum_0_sd); - opponent_sum_1_ref = std::ref(opponent_sum_1_sd); - opponent_sum_2_ref = std::ref(opponent_sum_2_sd); - } - } - while (true) { const auto& opponent_hand = hands_sorted[j]; const auto opponent_strength = (opponent_hand >> 16) & STRENGTH_MASK; @@ -944,6 +918,22 @@ static void compute_cfvs_showdown_3_vs_3(const Game& game, const Range& opponent break; } + if (draw_coefficient > 0) { + if (!is_below_flush && opponent_strength < WEAKEST_FLUSH) { + is_below_flush = true; + opponent_sum_0_ref = std::ref(opponent_sum_0_fd); + opponent_sum_1_ref = std::ref(opponent_sum_1_fd); + opponent_sum_2_ref = std::ref(opponent_sum_2_fd); + } + + if (!is_below_straight && opponent_strength < WEAKEST_STRAIGHT) { + is_below_straight = true; + opponent_sum_0_ref = std::ref(opponent_sum_0_sd); + opponent_sum_1_ref = std::ref(opponent_sum_1_sd); + opponent_sum_2_ref = std::ref(opponent_sum_2_sd); + } + } + const hand_t opponent_index = opponent_hand & ((1 << 16) - 1); const double prob = opponent_range.range[opponent_index]; @@ -974,29 +964,23 @@ static void compute_cfvs_showdown_3_vs_3(const Game& game, const Range& opponent opponent_sum_2[subs[2]]; if (draw_coefficient > 0) { - double weight = 1; - - if (hero_strength & FLUSH_DRAW_BIT) { - sum -= - (opponent_sum_0_fd + opponent_sum_0_sd - opponent_sum_1_fd[hero_cards[0]] - - opponent_sum_1_fd[hero_cards[1]] - opponent_sum_1_fd[hero_cards[2]] - - opponent_sum_1_sd[hero_cards[0]] - opponent_sum_1_sd[hero_cards[1]] - - opponent_sum_1_sd[hero_cards[2]] + opponent_sum_2_fd[subs[0]] + - opponent_sum_2_fd[subs[1]] + opponent_sum_2_fd[subs[2]] + opponent_sum_2_sd[subs[0]] + - opponent_sum_2_sd[subs[1]] + opponent_sum_2_sd[subs[2]]) * - flush_draw_weight; - weight -= flush_draw_weight; - } - - const auto num_sd = hero_strength & STRAIGHT_DRAW_MASK; - if (num_sd > 0) { - const double straight_draw_weight = weight * straight_draw_coefficient * num_sd; - sum -= - (opponent_sum_0_sd - opponent_sum_1_sd[hero_cards[0]] - - opponent_sum_1_sd[hero_cards[1]] - opponent_sum_1_sd[hero_cards[2]] + - opponent_sum_2_sd[subs[0]] + opponent_sum_2_sd[subs[1]] + opponent_sum_2_sd[subs[2]]) * - straight_draw_weight; - // weight -= straight_draw_weight; + if (is_below_flush) { + double weight = 1 - ((hero_strength & FLUSH_DRAW_BIT) ? flush_draw_weight : 0); + sum += + (opponent_sum_0_fd - opponent_sum_1_fd[hero_cards[0]] - + opponent_sum_1_fd[hero_cards[1]] - opponent_sum_1_fd[hero_cards[2]] + + opponent_sum_2_fd[subs[0]] + opponent_sum_2_fd[subs[1]] + opponent_sum_2_fd[subs[2]]) * + weight; + + if (is_below_straight) { + const auto num_sd = hero_strength & STRAIGHT_DRAW_MASK; + weight *= (1 - straight_draw_coefficient * num_sd); + sum += (opponent_sum_0_sd - opponent_sum_1_sd[hero_cards[0]] - + opponent_sum_1_sd[hero_cards[1]] - opponent_sum_1_sd[hero_cards[2]] + + opponent_sum_2_sd[subs[0]] + opponent_sum_2_sd[subs[1]] + + opponent_sum_2_sd[subs[2]]) * + weight; + } } } diff --git a/csrc/src/poker_hand.h b/csrc/src/poker_hand.h index 25e7e78..42b2bf9 100644 --- a/csrc/src/poker_hand.h +++ b/csrc/src/poker_hand.h @@ -83,6 +83,10 @@ class PokerHand { const auto flush_test = (misc_data_ + flush_adder) & flush_test_mask; if (!flush_test) { + if (strength > WEAKEST_FLUSH) { + return strength; + } + const auto flush_draw_test = (misc_data_ + flush_draw_adder) & flush_test_mask; const strength_t flush_draw_flag = flush_draw_test ? FLUSH_DRAW_BIT : 0; return strength | flush_draw_flag;