src/subgame_utils.cpp
// Copies source tree for the current node.  For successors of the current node, build according to
// the betting abstraction.
Copies source tree for the current node.  For successors of the current node, build according to
the betting abstraction.
Copies source tree for the current node . For successors of the current node build according to the betting abstraction .
BettingTrees *BuildHybridTree(const BettingAbstraction &betting_abstraction, int target_p,
			      Node *source, int last_bet_size, int num_street_bets, int num_bets) {
  BettingTreeBuilder betting_tree_builder(betting_abstraction, target_p);
  int csi = source->CallSuccIndex();
  bool has_call = csi != -1;
  int fsi = source->FoldSuccIndex();
  bool has_fold = fsi != -1;
  int num_succs = source->NumSuccs();
  int num_bet_succs = num_succs - (has_call ? 1 : 0) - (has_fold ? 1 : 0);
  int st = source->Street();
  int last_bet_to = source->LastBetTo();
  int player_acting = source->PlayerActing();
  int num_players = Game::NumPlayers();
  if (num_players > 2) {
    fprintf(stderr, "Node::StreetInitial() doesn't support multiplayer\n");
    exit(-1);
  }
  bool street_initial = source->StreetInitial();
  int num_players_to_act = street_initial ? 2 : 1;
  unique_ptr<bool []> folded(new bool[num_players]);
  for (int p = 0; p < num_players; ++p) folded[p] = false;
  int num_terminals = 0;
  string key;
  shared_ptr<Node> fold_succ, call_succ;
  vector< shared_ptr<Node> > bet_succs;
  if (has_call) {
    call_succ = betting_tree_builder.CreateMPCallSucc(st, last_bet_size, last_bet_to,
						      num_street_bets, num_bets, player_acting,
						      num_players_to_act, folded.get(), target_p,
						      &key, &num_terminals);
  }
  if (has_fold) {
    fold_succ = betting_tree_builder.CreateMPFoldSucc(st, last_bet_size, last_bet_to,
						      num_street_bets, num_bets, player_acting,
						      num_players_to_act, folded.get(), target_p,
						      &key, &num_terminals);
  }
  for (int i = 0; i < num_bet_succs; ++i) {
    int s = i + (has_call ? 1 : 0) + (has_fold ? 1 : 0);
    int bet_size = source->IthSucc(s)->LastBetTo() - source->LastBetTo();
    shared_ptr<Node> bet =
      betting_tree_builder.CreateMPSubtree(st, bet_size, last_bet_to + bet_size,
					   num_street_bets + 1, num_bets + 1, player_acting^1, 1,
					   folded.get(), -1, &key, &num_terminals);
    bet_succs.push_back(bet);
  }
  shared_ptr<Node> root(new Node(-1, st, player_acting, call_succ, fold_succ, &bet_succs, 2,
				 last_bet_to));
  return new BettingTrees(root.get());
}
BettingTrees * BuildHybridTree ( const BettingAbstraction & betting_abstraction , int target_p , Node * source , int last_bet_size , int num_street_bets , int num_bets ) { BettingTreeBuilder betting_tree_builder ( betting_abstraction , target_p ) ; int csi = source -> CallSuccIndex ( ) ; bool has_call = csi != -1 ; int fsi = source -> FoldSuccIndex ( ) ; bool has_fold = fsi != -1 ; int num_succs = source -> NumSuccs ( ) ; int num_bet_succs = num_succs - ( has_call ? 1 : 0 ) - ( has_fold ? 1 : 0 ) ; int st = source -> Street ( ) ; int last_bet_to = source -> LastBetTo ( ) ; int player_acting = source -> PlayerActing ( ) ; int num_players = Game :: NumPlayers ( ) ; if ( num_players > 2 ) { fprintf ( stderr , " \n " ) ; exit ( -1 ) ; } bool street_initial = source -> StreetInitial ( ) ; int num_players_to_act = street_initial ? 2 : 1 ; unique_ptr < bool [ ] > folded ( new bool [ num_players ] ) ; for ( int p = 0 ; p < num_players ; ++ p ) folded [ p ] = false ; int num_terminals = 0 ; string key ; shared_ptr < Node > fold_succ , call_succ ; vector < shared_ptr < Node > > bet_succs ; if ( has_call ) { call_succ = betting_tree_builder . CreateMPCallSucc ( st , last_bet_size , last_bet_to , num_street_bets , num_bets , player_acting , num_players_to_act , folded . get ( ) , target_p , & key , & num_terminals ) ; } if ( has_fold ) { fold_succ = betting_tree_builder . CreateMPFoldSucc ( st , last_bet_size , last_bet_to , num_street_bets , num_bets , player_acting , num_players_to_act , folded . get ( ) , target_p , & key , & num_terminals ) ; } for ( int i = 0 ; i < num_bet_succs ; ++ i ) { int s = i + ( has_call ? 1 : 0 ) + ( has_fold ? 1 : 0 ) ; int bet_size = source -> IthSucc ( s ) -> LastBetTo ( ) - source -> LastBetTo ( ) ; shared_ptr < Node > bet = betting_tree_builder . CreateMPSubtree ( st , bet_size , last_bet_to + bet_size , num_street_bets + 1 , num_bets + 1 , player_acting ^ 1 , 1 , folded . get ( ) , -1 , & key , & num_terminals ) ; bet_succs . push_back ( bet ) ; } shared_ptr < Node > root ( new Node ( -1 , st , player_acting , call_succ , fold_succ , & bet_succs , 2 , last_bet_to ) ) ; return new BettingTrees ( root . get ( ) ) ; }
Copies source tree for the current node.
Copies source tree for the current node .