src/subgame_utils.cpp
// Builds a subtree rooted at a street-initial node on backup_st.  We take a path from a source
// tree as input.  This path is a sequence of nodes from the root of the source tree to some
// nonterminal node that is on backup_st or later.  The new subtree we create is a) modeled
// on the source tree along the subpart of the input path starting at backup_st, and b) dictated
// by the input betting abstraction for the remainder.
// What should I do at each step?
// If the source node calls:
//   Create a call node
// Otherwise:
//   Create a call subtree with the given betting abstraction
// If the source node bets:
//   Create a bet node with the given bet size
// Otherwise:
//   Create one or more bet subtrees with the given betting abstraction
// If the source node has a fold succ
//   Create a fold succ
// Create a call node, a fold node and a bet node?  If the source node made a bet, then get the
Builds a subtree rooted at a street-initial node on backup_st.  We take a path from a source
tree as input.  This path is a sequence of nodes from the root of the source tree to some
nonterminal node that is on backup_st or later.  The new subtree we create is a) modeled
on the source tree along the subpart of the input path starting at backup_st, and b) dictated
by the input betting abstraction for the remainder.
What should I do at each step.
If the source node calls:
Create a call node
Otherwise:
Create a call subtree with the given betting abstraction
If the source node bets:
Create a bet node with the given bet size
Otherwise:
Create one or more bet subtrees with the given betting abstraction
If the source node has a fold succ
Create a fold succ
Create a call node, a fold node and a bet node.  If the source node made a bet, then get the
Builds a subtree rooted at a street - initial node on backup_st . We take a path from a source tree as input . This path is a sequence of nodes from the root of the source tree to some nonterminal node that is on backup_st or later . The new subtree we create is a ) modeled on the source tree along the subpart of the input path starting at backup_st and b ) dictated by the input betting abstraction for the remainder . What should I do at each step . If the source node calls : Create a call node Otherwise : Create a call subtree with the given betting abstraction If the source node bets : Create a bet node with the given bet size Otherwise : Create one or more bet subtrees with the given betting abstraction If the source node has a fold succ Create a fold succ Create a call node a fold node and a bet node . If the source node made a bet then get the
BettingTrees *BuildHybridTreeBackup(const BettingAbstraction &betting_abstraction, int target_p,
				    const vector<Node *> &source_path, int backup_st) {
  BettingTreeBuilder betting_tree_builder(betting_abstraction, target_p);
  int sz = source_path.size();
  int num_bets = 0, i;
  for (i = 0; i < sz; ++i) {
    Node *node = source_path[i];
    if (node->Street() == backup_st) break;
    if (i < sz - 1) {
      Node *next_node = source_path[i+1];
      int num_succs = node->NumSuccs();
      int s;
      for (s = 0; s < num_succs; ++s) {
	if (node->IthSucc(s) == next_node) break;
      }
      if (s == num_succs) {
	fprintf(stderr, "Couldn't connect node to next node\n");
	exit(-1);
      }
      if (s != node->CallSuccIndex() && s != node->FoldSuccIndex()) ++num_bets;
    }
  }
  if (i == sz) {
    fprintf(stderr, "No node on backup street on path\n");
    exit(-1);
  }
  unique_ptr<bool []> folded(new bool[2]);
  string key;
  for (int p = 0; p < 2; ++p) folded[p] = false;
  int num_terminals = 0, last_bet_size = 0, num_street_bets = 0, num_players_to_act = 2;
  int last_st = backup_st;
  for (int j = i; j < sz - 1; ++j) {
    Node *node = source_path[j];
    Node *next_node = source_path[j+1];
    int num_succs = node->NumSuccs();
    int s;
    for (s = 0; s < num_succs; ++s) {
      if (node->IthSucc(s) == next_node) break;
    }
    if (s == num_succs) {
      fprintf(stderr, "Couldn't connect node to next node\n");
      exit(-1);
    }
    if (s == node->FoldSuccIndex()) {
      fprintf(stderr, "Shouldn't see fold along path\n");
      exit(-1);
    }
    int st = node->Street();
    if (st > last_st) {
      num_street_bets = 0;
      last_bet_size = 0;
      num_players_to_act = 2;
      st = last_st;
    }
    int pa = node->PlayerActing();
    shared_ptr<Node> call_succ, fold_succ;
    if (node->HasCallSucc()) {
      call_succ = betting_tree_builder.CreateMPCallSucc(st, last_bet_size, node->LastBetTo(),
							num_street_bets, num_bets, pa,
							num_players_to_act, folded.get(), target_p,
							&key, &num_terminals);
    }
    if (node->HasFoldSucc()) {
      fold_succ = betting_tree_builder.CreateMPFoldSucc(st, last_bet_size, node->LastBetTo(),
							num_street_bets, num_bets, pa,
							num_players_to_act, folded.get(), target_p,
							&key, &num_terminals);
    }
    int new_bet_size;
    if (s == node->CallSuccIndex()) {
      new_bet_size = 0;
      num_players_to_act = 1;
    } else if (s == node->FoldSuccIndex()) {
    } else {
      new_bet_size = next_node->LastBetTo() - node->LastBetTo();
      ++num_street_bets;
      num_players_to_act = 1;
    }
    last_bet_size = new_bet_size;
    vector< shared_ptr<Node> > bet_succs;
    shared_ptr<Node> call_succ;
    shared_ptr<Node> fold_succ;
    vector< shared_ptr<Node> > bet_succs;
    CreateMPSuccs(st, last_bet_size, bet_to, num_street_bets, num_bets, player_acting,
		  num_players_to_act, folded, target_player, key, terminal_id, &call_succ,
		  &fold_succ, &bet_succs);
    if (s == node->CallSuccIndex()) {
    }
  }
}
BettingTrees * BuildHybridTreeBackup ( const BettingAbstraction & betting_abstraction , int target_p , const vector < Node * > & source_path , int backup_st ) { BettingTreeBuilder betting_tree_builder ( betting_abstraction , target_p ) ; int sz = source_path . size ( ) ; int num_bets = 0 , i ; for ( i = 0 ; i < sz ; ++ i ) { Node * node = source_path [ i ] ; if ( node -> Street ( ) == backup_st ) break ; if ( i < sz - 1 ) { Node * next_node = source_path [ i + 1 ] ; int num_succs = node -> NumSuccs ( ) ; int s ; for ( s = 0 ; s < num_succs ; ++ s ) { if ( node -> IthSucc ( s ) == next_node ) break ; } if ( s == num_succs ) { fprintf ( stderr , " \n " ) ; exit ( -1 ) ; } if ( s != node -> CallSuccIndex ( ) && s != node -> FoldSuccIndex ( ) ) ++ num_bets ; } } if ( i == sz ) { fprintf ( stderr , " \n " ) ; exit ( -1 ) ; } unique_ptr < bool [ ] > folded ( new bool [ 2 ] ) ; string key ; for ( int p = 0 ; p < 2 ; ++ p ) folded [ p ] = false ; int num_terminals = 0 , last_bet_size = 0 , num_street_bets = 0 , num_players_to_act = 2 ; int last_st = backup_st ; for ( int j = i ; j < sz - 1 ; ++ j ) { Node * node = source_path [ j ] ; Node * next_node = source_path [ j + 1 ] ; int num_succs = node -> NumSuccs ( ) ; int s ; for ( s = 0 ; s < num_succs ; ++ s ) { if ( node -> IthSucc ( s ) == next_node ) break ; } if ( s == num_succs ) { fprintf ( stderr , " \n " ) ; exit ( -1 ) ; } if ( s == node -> FoldSuccIndex ( ) ) { fprintf ( stderr , " \n " ) ; exit ( -1 ) ; } int st = node -> Street ( ) ; if ( st > last_st ) { num_street_bets = 0 ; last_bet_size = 0 ; num_players_to_act = 2 ; st = last_st ; } int pa = node -> PlayerActing ( ) ; shared_ptr < Node > call_succ , fold_succ ; if ( node -> HasCallSucc ( ) ) { call_succ = betting_tree_builder . CreateMPCallSucc ( st , last_bet_size , node -> LastBetTo ( ) , num_street_bets , num_bets , pa , num_players_to_act , folded . get ( ) , target_p , & key , & num_terminals ) ; } if ( node -> HasFoldSucc ( ) ) { fold_succ = betting_tree_builder . CreateMPFoldSucc ( st , last_bet_size , node -> LastBetTo ( ) , num_street_bets , num_bets , pa , num_players_to_act , folded . get ( ) , target_p , & key , & num_terminals ) ; } int new_bet_size ; if ( s == node -> CallSuccIndex ( ) ) { new_bet_size = 0 ; num_players_to_act = 1 ; } else if ( s == node -> FoldSuccIndex ( ) ) { } else { new_bet_size = next_node -> LastBetTo ( ) - node -> LastBetTo ( ) ; ++ num_street_bets ; num_players_to_act = 1 ; } last_bet_size = new_bet_size ; vector < shared_ptr < Node > > bet_succs ; shared_ptr < Node > call_succ ; shared_ptr < Node > fold_succ ; vector < shared_ptr < Node > > bet_succs ; CreateMPSuccs ( st , last_bet_size , bet_to , num_street_bets , num_bets , player_acting , num_players_to_act , folded , target_player , key , terminal_id , & call_succ , & fold_succ , & bet_succs ) ; if ( s == node -> CallSuccIndex ( ) ) { } } }
Builds a subtree rooted at a street-initial node on backup_st.
Builds a subtree rooted at a street - initial node on backup_st .
// Should I create node or subtree? // call_succ.reset(new Node(-1, st, pa, call_succ, fold_succ, &bet_succs, num_rem, bet_to));