src/betting_tree_builder.cpp
// To handle reentrant trees we keep a boolean array of nodes that have
// already been visited.  Note that even if a node has already been visited,
// we still write out the properties of the node (ID, flags, pot size, etc.).
// But we prevent ourselves from redundantly writing out the subtree below
// the node more than once.
To handle reentrant trees we keep a boolean array of nodes that have
already been visited.  Note that even if a node has already been visited,
we still write out the properties of the node (ID, flags, pot size, etc.).
But we prevent ourselves from redundantly writing out the subtree below
the node more than once.
To handle reentrant trees we keep a boolean array of nodes that have already been visited . Note that even if a node has already been visited we still write out the properties of the node ( ID flags pot size etc . ) . But we prevent ourselves from redundantly writing out the subtree below the node more than once .
void BettingTreeBuilder::Write(Node *node, vector< vector<int> > *num_nonterminals,
			       Writer *writer) {
  int st = node->Street();
  int id = node->ID();
  int pa = node->PlayerActing();
  bool nt_first_seen = (id == -1);
  if (nt_first_seen) {
    id = (*num_nonterminals)[pa][st]++;
    node->SetNonterminalID(id);
  }
  writer->WriteUnsignedInt(id);
  writer->WriteUnsignedShort(node->LastBetTo());
  writer->WriteUnsignedShort(node->NumSuccs());
  writer->WriteUnsignedShort(node->Flags());
  writer->WriteUnsignedChar(pa);
  writer->WriteUnsignedChar(node->NumRemaining());
  if (node->Terminal()) {
    return;
  }
  if (! nt_first_seen) return;
  int num_succs = node->NumSuccs();
  for (int s = 0; s < num_succs; ++s) {
    Write(node->IthSucc(s), num_nonterminals, writer);
  }
}
void BettingTreeBuilder :: Write ( Node * node , vector < vector < int > > * num_nonterminals , Writer * writer ) { int st = node -> Street ( ) ; int id = node -> ID ( ) ; int pa = node -> PlayerActing ( ) ; bool nt_first_seen = ( id == -1 ) ; if ( nt_first_seen ) { id = ( * num_nonterminals ) [ pa ] [ st ] ++ ; node -> SetNonterminalID ( id ) ; } writer -> WriteUnsignedInt ( id ) ; writer -> WriteUnsignedShort ( node -> LastBetTo ( ) ) ; writer -> WriteUnsignedShort ( node -> NumSuccs ( ) ) ; writer -> WriteUnsignedShort ( node -> Flags ( ) ) ; writer -> WriteUnsignedChar ( pa ) ; writer -> WriteUnsignedChar ( node -> NumRemaining ( ) ) ; if ( node -> Terminal ( ) ) { return ; } if ( ! nt_first_seen ) return ; int num_succs = node -> NumSuccs ( ) ; for ( int s = 0 ; s < num_succs ; ++ s ) { Write ( node -> IthSucc ( s ) , num_nonterminals , writer ) ; } }
To handle reentrant trees we keep a boolean array of nodes that have
already been visited.
To handle reentrant trees we keep a boolean array of nodes that have already been visited .
// Assign IDs during writing