-/// Book::read_integer() reads size chars from the file stream
-/// and converts them in an integer number.
-
-uint64_t Book::read_integer(int size) {
-
- char buf[8];
- read(buf, size);
-
- // Numbers are stored on disk as a binary byte stream
- uint64_t n = 0;
- for (int i = 0; i < size; i++)
- n = (n << 8) + (unsigned char)buf[i];
-
- return n;
-}
-
-
-////
-//// Local definitions
-////
-
-namespace {
-
- uint64_t book_key(const Position& pos) {
-
- uint64_t result = 0;
-
- for (Color c = WHITE; c <= BLACK; c++)
- {
- Bitboard b = pos.pieces_of_color(c);
-
- while (b)
- {
- Square s = pop_1st_bit(&b);
- Piece p = pos.piece_on(s);
-
- assert(piece_is_ok(p));
- assert(color_of_piece(p) == c);
-
- result ^= book_piece_key(p, s);
- }
- }
- result ^= book_castle_key(pos);
- result ^= book_ep_key(pos);
- result ^= book_color_key(pos);
- return result;
- }
-
-
- uint64_t book_piece_key(Piece p, Square s) {
-
- /// Convert pieces to the range 0..11
- static const int PieceTo12[] = { 0, 0, 2, 4, 6, 8, 10, 0, 0, 1, 3, 5, 7, 9, 11 };
-
- return Random64[RandomPiece + (PieceTo12[int(p)]^1) * 64 + int(s)];
- }
-