Skip to content

Commit

Permalink
Fix many
Browse files Browse the repository at this point in the history
  • Loading branch information
b-inary committed Feb 1, 2024
1 parent ac01674 commit 767b5c8
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 106 deletions.
196 changes: 90 additions & 106 deletions csrc/src/equity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];

Expand Down Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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];

Expand All @@ -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;
}
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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];

Expand Down Expand Up @@ -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;
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions csrc/src/poker_hand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 767b5c8

Please sign in to comment.