src/makebook.cpp
// Add move to our in-memory data structure
Add move to our in-memory data structure
Add move to our in - memory data structure
static void
add_move(const Board & board, const MoveListEntry &m, bool is_first_file,
         const Variation &var)
{
#ifdef _TRACE
   cout << "adding move ";
   Notation::image(board,m.move,Notation::SAN_OUT,cout);
   cout << endl;
#endif
   const int move_index = m.index;
   const int recommend = m.rec;
   map<uint64,BookEntry *>::const_iterator it =
      hashTable->find(board.hashCode());
   BookEntry *be;
   if (it == hashTable->end())
      be = NULL;
   else
      be = (*it).second;
   if (be == NULL) {
       BookEntry *new_entry;
       try {
          new_entry = new BookEntry(recommend,
                                    var.eval, m.moveEval, var.result,
                                    move_index, NULL, is_first_file);
       } catch(std::bad_alloc) {
          cerr << "out of memory!" << endl;
          exit(-1);
       }
      (*hashTable)[board.hashCode()] = new_entry;
#ifdef _TRACE
      cout << "inserting position: " <<
         " h:" << (hex) << Bitboard(board.hashCode()).hivalue() <<
         Bitboard(board.hashCode()).lovalue() << (dec) <<
         " index = " << (int)move_index << " from bk = " << (int)is_first_file <<
         " recommend=" << (int)recommend << endl;
#endif
   }
   else {
      BookEntry *p = be;
      int found = 0;
      while (p && !found) {
         if (p->move_index == move_index) {
            ++found; break;
         }
         p = p->next;
      }
      if (found) {
         p->count++; 
         if (var.result == White_Win) {
            p->white_win_loss++;
         }
         else if (var.result == Black_Win) {
            p->white_win_loss--;
         }
         if (m.rec != book::NO_RECOMMEND &&
             p->rec == book::NO_RECOMMEND) {
            p->rec = m.rec;
         }
         if (m.moveEval != NO_MOVE_EVAL && p->moveEval == NO_MOVE_EVAL) {
            p->moveEval = m.moveEval;
         }
#ifdef _TRACE
         cout << "updating: " <<
            " h:" << (hex) << Bitboard(board.hashCode()).hivalue() <<
            Bitboard(board.hashCode()).lovalue() << (dec) <<
            " index = " << (int)move_index << 
            " first = " << (int)is_first_file <<
            " winloss=" << p->white_win_loss <<
            " rec=" << p->rec <<
            " count=" << p->count << endl;
#endif
      }
      else {
#ifdef _TRACE
         cout << "inserting move: " <<
            " h:" << (hex) << Bitboard(board.hashCode()).hivalue() <<
            Bitboard(board.hashCode()).lovalue() << (dec) <<
            " index = " << (int)move_index << " first = " << (int)is_first_file <<
            " recommend=" << (int)recommend << endl;
#endif
         BookEntry *new_entry;
         try {
            new_entry = new BookEntry(recommend,
                                      var.eval, m.moveEval, var.result,
                                      move_index, be, is_first_file);
         } catch(std::bad_alloc) {
            cerr << "out of memory!" << endl;
            exit(-1);
         }
         (*hashTable)[board.hashCode()] = new_entry;
      }
   }
}
static void add_move ( const Board & board , const MoveListEntry & m , bool is_first_file , const Variation & var ) { #ifdef _TRACE cout << " " ; Notation :: image ( board , m . move , Notation :: SAN_OUT , cout ) ; cout << endl ; #endif const int move_index = m . index ; const int recommend = m . rec ; map < uint64 , BookEntry * > :: const_iterator it = hashTable -> find ( board . hashCode ( ) ) ; BookEntry * be ; if ( it == hashTable -> end ( ) ) be = NULL ; else be = ( * it ) . second ; if ( be == NULL ) { BookEntry * new_entry ; try { new_entry = new BookEntry ( recommend , var . eval , m . moveEval , var . result , move_index , NULL , is_first_file ) ; } catch ( std :: bad_alloc ) { cerr << " " << endl ; exit ( -1 ) ; } ( * hashTable ) [ board . hashCode ( ) ] = new_entry ; #ifdef _TRACE cout << " " << " " << ( hex ) << Bitboard ( board . hashCode ( ) ) . hivalue ( ) << Bitboard ( board . hashCode ( ) ) . lovalue ( ) << ( dec ) << " " << ( int ) move_index << " " << ( int ) is_first_file << " " << ( int ) recommend << endl ; #endif } else { BookEntry * p = be ; int found = 0 ; while ( p && ! found ) { if ( p -> move_index == move_index ) { ++ found ; break ; } p = p -> next ; } if ( found ) { p -> count ++ ; if ( var . result == White_Win ) { p -> white_win_loss ++ ; } else if ( var . result == Black_Win ) { p -> white_win_loss -- ; } if ( m . rec != book :: NO_RECOMMEND && p -> rec == book :: NO_RECOMMEND ) { p -> rec = m . rec ; } if ( m . moveEval != NO_MOVE_EVAL && p -> moveEval == NO_MOVE_EVAL ) { p -> moveEval = m . moveEval ; } #ifdef _TRACE cout << " " << " " << ( hex ) << Bitboard ( board . hashCode ( ) ) . hivalue ( ) << Bitboard ( board . hashCode ( ) ) . lovalue ( ) << ( dec ) << " " << ( int ) move_index << " " << ( int ) is_first_file << " " << p -> white_win_loss << " " << p -> rec << " " << p -> count << endl ; #endif } else { #ifdef _TRACE cout << " " << " " << ( hex ) << Bitboard ( board . hashCode ( ) ) . hivalue ( ) << Bitboard ( board . hashCode ( ) ) . lovalue ( ) << ( dec ) << " " << ( int ) move_index << " " << ( int ) is_first_file << " " << ( int ) recommend << endl ; #endif BookEntry * new_entry ; try { new_entry = new BookEntry ( recommend , var . eval , m . moveEval , var . result , move_index , be , is_first_file ) ; } catch ( std :: bad_alloc ) { cerr << " " << endl ; exit ( -1 ) ; } ( * hashTable ) [ board . hashCode ( ) ] = new_entry ; } } }
Add move to our in-memory data structure
Add move to our in - memory data structure
// position not found in hashtable // update existing entry // Move already in hash table // set explicit weight if not set already // set move eval if not set already // Position is in hashtable, but not with this move.