src/betting_tree.cpp
// Works for no-limit now?
// Takes a string like "BC CB" or "B100C B50" and returns the node named by
// that string
Works for no-limit now.
Takes a string like "BC CB" or "B100C B50" and returns the node named by
that string
Works for no - limit now . Takes a string like " BC CB " or " B100C B50 " and returns the node named by that string
Node *BettingTree::GetNodeFromName(const char *str, Node *node) {
  char c = *str;
  if (c == 0 || c == '\n' || (c == ' ' && (str[1] == 0 || str[1] == '\n'))) {
    return node;
  }
  if (c == ' ') return GetNodeFromName(str + 1, node);
  Node *succ;
  const char *next_str;
  if (c == 'F') {
    int s = node->FoldSuccIndex();
    succ = node->IthSucc(s);
    next_str = str + 1;
  } else if (c == 'C') {
    int s = node->CallSuccIndex();
    succ = node->IthSucc(s);
    next_str = str + 1;
  } else if (c == 'B') {
    int i = 1;
    while (str[i] >= '0' && str[i] <= '9') ++i;
    if (i == 1) {
      succ = node->IthSucc(node->NumSuccs() - 1);
    } else {
      char buf[20];
      if (i > 10) {
	fprintf(stderr, "Too big a bet size: %s\n", str);
	exit(-1);
      }
      memcpy(buf, str + 1, i - 1);
      buf[i-1] = 0;
      int bet_size;
      if (sscanf(buf, "%i", &bet_size) != 1) {
	fprintf(stderr, "Couldn't parse bet size: %s\n", str);
	exit(-1);
      }
      int s = node->CallSuccIndex();
      Node *before_call_succ = node->IthSucc(s);
      int before_pot_size = before_call_succ->PotSize();
      int num_succs = node->NumSuccs();
      int j;
      for (j = 0; j < num_succs; ++j) {
	Node *jth_succ = node->IthSucc(j);
	int s2 = jth_succ->CallSuccIndex();
	if (s2 == -1) continue;
	Node *call_succ = jth_succ->IthSucc(s2);
	int after_pot_size = call_succ->PotSize();
	int this_bet_size = (after_pot_size - before_pot_size) / 2;
	if (this_bet_size == bet_size) break;
      }
      if (j == num_succs) {
	fprintf(stderr, "Couldn't find node with bet size %i\n", bet_size);
	exit(-1);
      }
      succ = node->IthSucc(j);
    }
    next_str = str + i;
  } else {
    fprintf(stderr, "Couldn't parse node name from %s\n", str);
    exit(-1);
  }
  if (succ == NULL) {
    return NULL;
  }
  return GetNodeFromName(next_str, succ);
}
Node * BettingTree :: GetNodeFromName ( const char * str , Node * node ) { char c = * str ; if ( c == 0 || c == ' \n ' || ( c == ' ' && ( str [ 1 ] == 0 || str [ 1 ] == ' \n ' ) ) ) { return node ; } if ( c == ' ' ) return GetNodeFromName ( str + 1 , node ) ; Node * succ ; const char * next_str ; if ( c == ' ' ) { int s = node -> FoldSuccIndex ( ) ; succ = node -> IthSucc ( s ) ; next_str = str + 1 ; } else if ( c == ' ' ) { int s = node -> CallSuccIndex ( ) ; succ = node -> IthSucc ( s ) ; next_str = str + 1 ; } else if ( c == ' ' ) { int i = 1 ; while ( str [ i ] >= ' ' && str [ i ] <= ' ' ) ++ i ; if ( i == 1 ) { succ = node -> IthSucc ( node -> NumSuccs ( ) - 1 ) ; } else { char buf [ 20 ] ; if ( i > 10 ) { fprintf ( stderr , " \n " , str ) ; exit ( -1 ) ; } memcpy ( buf , str + 1 , i - 1 ) ; buf [ i - 1 ] = 0 ; int bet_size ; if ( sscanf ( buf , " " , & bet_size ) != 1 ) { fprintf ( stderr , " \n " , str ) ; exit ( -1 ) ; } int s = node -> CallSuccIndex ( ) ; Node * before_call_succ = node -> IthSucc ( s ) ; int before_pot_size = before_call_succ -> PotSize ( ) ; int num_succs = node -> NumSuccs ( ) ; int j ; for ( j = 0 ; j < num_succs ; ++ j ) { Node * jth_succ = node -> IthSucc ( j ) ; int s2 = jth_succ -> CallSuccIndex ( ) ; if ( s2 == -1 ) continue ; Node * call_succ = jth_succ -> IthSucc ( s2 ) ; int after_pot_size = call_succ -> PotSize ( ) ; int this_bet_size = ( after_pot_size - before_pot_size ) / 2 ; if ( this_bet_size == bet_size ) break ; } if ( j == num_succs ) { fprintf ( stderr , " \n " , bet_size ) ; exit ( -1 ) ; } succ = node -> IthSucc ( j ) ; } next_str = str + i ; } else { fprintf ( stderr , " \n " , str ) ; exit ( -1 ) ; } if ( succ == NULL ) { return NULL ; } return GetNodeFromName ( next_str , succ ) ; }
Works for no-limit now?
Works for no - limit now?
// Allow an unconsumed space at the end of the name.  So we can find a node // either by the strictly proper name "CC " or by "CC". // Must be limit tree // B43 - i will be 3