src/agent.cpp
// Return true if we take an action.
Return true if we take an action.
Return true if we take an action .
bool Agent::ProcessMatchState(const MatchState &match_state, CFRValues **resolved_strategy,
			      bool *call, bool *fold, int *bet_size) {
  int hand_no = match_state.HandNo();
  srand48_r(hand_no, &rand_buf_);
  bool we_p1 = match_state.P1();
  int we_p = we_p1 ? 1 : 0;
  const string &action = match_state.Action();
  Card hole_cards[2];
  hole_cards[0] = match_state.OurHi();
  hole_cards[1] = match_state.OurLo();
  const Card *board = match_state.Board();
  int st = match_state.Street();
  unique_ptr<int []> buckets(new int[st + 1]);
  SetBuckets(st, board, hole_cards, buckets.get());
  Node *raise_node;
  bool mapped_bet_to_closing_call;
  Node *node = ProcessAction(action, we_p, buckets.get(), &raise_node, &mapped_bet_to_closing_call);
  fprintf(stderr, "Back from ProcessAction\n");
  *call = false;
  *fold = false;
  *bet_size = 0;
#if 0
  if (node->Terminal()) {
    fprintf(stderr, "At terminal node; exiting\n");
    exit(-1);
  }
#endif
#if 0
  if (node->PlayerActing() != we_p) {
    fprintf(stderr, "Not our action; returning false\n");
    return false;
  }
#endif
#if 0
  int num_succs = node->NumSuccs();
  if (num_succs == 0) {
    fprintf(stderr, "Zero succ node that is not terminal?!?\n");
    return false;
  }
  if (num_succs == 1) {
    *call = true;
    return true;
  }
#endif
#if 0
  int nst = node->Street();
  if (nst != st) {
    fprintf(stderr, "nst %i != st %i?!?\n", nst, st);
    exit(-1);
  }
#endif
  Node *next_node = ChooseOurAction(node, raise_node, buckets.get(), mapped_bet_to_closing_call);
  int csi = node->CallSuccIndex();
  int fsi = node->FoldSuccIndex();
  if (next_node == node) {
    *call = true;
    return true;
  } else if (csi >= 0 && next_node == node->IthSucc(csi)) {
    *call = true;
    return true;
  } else if (fsi >= 0 && next_node == node->IthSucc(fsi)) {
    *fold = true;
    return true;
  }
  fprintf(stderr, "Betting %i small blinds\n", next_node->LastBetTo() - node->LastBetTo());
  *bet_size = (next_node->LastBetTo() - node->LastBetTo()) * small_blind_;
  return true;
}
bool Agent :: ProcessMatchState ( const MatchState & match_state , CFRValues * * resolved_strategy , bool * call , bool * fold , int * bet_size ) { int hand_no = match_state . HandNo ( ) ; srand48_r ( hand_no , & rand_buf_ ) ; bool we_p1 = match_state . P1 ( ) ; int we_p = we_p1 ? 1 : 0 ; const string & action = match_state . Action ( ) ; Card hole_cards [ 2 ] ; hole_cards [ 0 ] = match_state . OurHi ( ) ; hole_cards [ 1 ] = match_state . OurLo ( ) ; const Card * board = match_state . Board ( ) ; int st = match_state . Street ( ) ; unique_ptr < int [ ] > buckets ( new int [ st + 1 ] ) ; SetBuckets ( st , board , hole_cards , buckets . get ( ) ) ; Node * raise_node ; bool mapped_bet_to_closing_call ; Node * node = ProcessAction ( action , we_p , buckets . get ( ) , & raise_node , & mapped_bet_to_closing_call ) ; fprintf ( stderr , " \n " ) ; * call = false ; * fold = false ; * bet_size = 0 ; #if 0 if ( node -> Terminal ( ) ) { fprintf ( stderr , " \n " ) ; exit ( -1 ) ; } #endif #if 0 if ( node -> PlayerActing ( ) != we_p ) { fprintf ( stderr , " \n " ) ; return false ; } #endif #if 0 int num_succs = node -> NumSuccs ( ) ; if ( num_succs == 0 ) { fprintf ( stderr , " \n " ) ; return false ; } if ( num_succs == 1 ) { * call = true ; return true ; } #endif #if 0 int nst = node -> Street ( ) ; if ( nst != st ) { fprintf ( stderr , " \n " , nst , st ) ; exit ( -1 ) ; } #endif Node * next_node = ChooseOurAction ( node , raise_node , buckets . get ( ) , mapped_bet_to_closing_call ) ; int csi = node -> CallSuccIndex ( ) ; int fsi = node -> FoldSuccIndex ( ) ; if ( next_node == node ) { * call = true ; return true ; } else if ( csi >= 0 && next_node == node -> IthSucc ( csi ) ) { * call = true ; return true ; } else if ( fsi >= 0 && next_node == node -> IthSucc ( fsi ) ) { * fold = true ; return true ; } fprintf ( stderr , " \n " , next_node -> LastBetTo ( ) - node -> LastBetTo ( ) ) ; * bet_size = ( next_node -> LastBetTo ( ) - node -> LastBetTo ( ) ) * small_blind_ ; return true ; }
Return true if we take an action.
Return true if we take an action .
// In our reconstruction of the action (inside ProcessAction()) we choose our actions // randomly.  We need to be able to reconstruct the action of the hand and make the same // choices each time.  For this to work, I need to seed the RNG here consistently. // This can happen if we translate a bet to a call, and the call leads to showdown // This can happen if we translate a bet to a call, and the call ends the street. // This is possible if we map an opponent's bet to a street-ending call. // This is the case where we mapped an opponent's bet to a street-ending call (and we decided // not to raise). // Should we bet the amount dictated by our abstraction or the pot fraction? // Maybe the latter.