src/head_to_head.cpp
// Compute outcome from B's perspective
Compute outcome from B's perspective
Compute outcome from B ' s perspective
void PlayerThread::Fold(Node *a_node, Node *b_node, const ReachProbs &reach_probs) {
  Card max_card1 = Game::MaxCard() + 1;
  double half_pot = a_node->LastBetTo();
  int rem_p = a_node->PlayerActing();
  if (b_pos_ != rem_p) {
    half_pot = -half_pot;
  }
  int max_street = Game::MaxStreet();
  const CanonicalCards *hands = street_hands_[max_street].get();
  double sum_our_vals = 0, sum_joint_probs = 0;
  double *a_probs = reach_probs.Get(b_pos_^1).get();
  double *b_probs = reach_probs.Get(b_pos_).get();
  unique_ptr<double []> cum_opp_card_probs(new double[52]);
  unique_ptr<double []> total_opp_card_probs(new double[52]);
  for (Card c = 0; c < max_card1; ++c) {
    cum_opp_card_probs[c] = 0;
    total_opp_card_probs[c] = 0;
  }
  double sum_opp_probs = 0;
  int num_hole_card_pairs = Game::NumHoleCardPairs(max_street);
  for (int hcp = 0; hcp < num_hole_card_pairs; ++hcp) {
    const Card *cards = hands->Cards(hcp);
    Card hi = cards[0];
    Card lo = cards[1];
    int enc = hi * max_card1 + lo;
    double opp_prob = a_probs[enc];
    total_opp_card_probs[hi] += opp_prob;
    total_opp_card_probs[lo] += opp_prob;
    sum_opp_probs += opp_prob;
  }
  for (int i = 0; i < num_hole_card_pairs; ++i) {
    const Card *cards = hands->Cards(i);
    Card hi = cards[0];
    Card lo = cards[1];
    int enc = hi * max_card1 + lo;
    double our_prob = b_probs[enc];
    double sum_consistent_opp_probs = sum_opp_probs + a_probs[enc] -
      total_opp_card_probs[hi] - total_opp_card_probs[lo];
    sum_our_vals += our_prob * half_pot * sum_consistent_opp_probs;
    sum_joint_probs += our_prob * sum_consistent_opp_probs;    
  }
  sum_b_outcomes_ += sum_our_vals;
  sum_weights_ += sum_joint_probs;
}
void PlayerThread :: Fold ( Node * a_node , Node * b_node , const ReachProbs & reach_probs ) { Card max_card1 = Game :: MaxCard ( ) + 1 ; double half_pot = a_node -> LastBetTo ( ) ; int rem_p = a_node -> PlayerActing ( ) ; if ( b_pos_ != rem_p ) { half_pot = - half_pot ; } int max_street = Game :: MaxStreet ( ) ; const CanonicalCards * hands = street_hands_ [ max_street ] . get ( ) ; double sum_our_vals = 0 , sum_joint_probs = 0 ; double * a_probs = reach_probs . Get ( b_pos_ ^ 1 ) . get ( ) ; double * b_probs = reach_probs . Get ( b_pos_ ) . get ( ) ; unique_ptr < double [ ] > cum_opp_card_probs ( new double [ 52 ] ) ; unique_ptr < double [ ] > total_opp_card_probs ( new double [ 52 ] ) ; for ( Card c = 0 ; c < max_card1 ; ++ c ) { cum_opp_card_probs [ c ] = 0 ; total_opp_card_probs [ c ] = 0 ; } double sum_opp_probs = 0 ; int num_hole_card_pairs = Game :: NumHoleCardPairs ( max_street ) ; for ( int hcp = 0 ; hcp < num_hole_card_pairs ; ++ hcp ) { const Card * cards = hands -> Cards ( hcp ) ; Card hi = cards [ 0 ] ; Card lo = cards [ 1 ] ; int enc = hi * max_card1 + lo ; double opp_prob = a_probs [ enc ] ; total_opp_card_probs [ hi ] += opp_prob ; total_opp_card_probs [ lo ] += opp_prob ; sum_opp_probs += opp_prob ; } for ( int i = 0 ; i < num_hole_card_pairs ; ++ i ) { const Card * cards = hands -> Cards ( i ) ; Card hi = cards [ 0 ] ; Card lo = cards [ 1 ] ; int enc = hi * max_card1 + lo ; double our_prob = b_probs [ enc ] ; double sum_consistent_opp_probs = sum_opp_probs + a_probs [ enc ] - total_opp_card_probs [ hi ] - total_opp_card_probs [ lo ] ; sum_our_vals += our_prob * half_pot * sum_consistent_opp_probs ; sum_joint_probs += our_prob * sum_consistent_opp_probs ; } sum_b_outcomes_ += sum_our_vals ; sum_weights_ += sum_joint_probs ; }
Compute outcome from B's perspective
Compute outcome from B ' s perspective
// Player acting encodes player remaining at fold nodes // Outcomes are from B's perspective // B has folded // Note: we are going to iterate through max street hands even if this is a pre-max-street // node. // double *a_probs = b_pos_ == 0 ? reach_probs[1].get() : reach_probs[0].get(); // double *b_probs = b_pos_ == 0 ? reach_probs[0].get() : reach_probs[1].get(); // Always iterate through hole card pairs consistent with the sampled *max street* board, even if // this is a pre-max-street node. // This is the sum of all the A reach probabilities consistent with B holding <hi, lo>.