-////
-//// Local definitions
-////
-
-namespace {
-
- uint64_t book_key(const Position& pos) {
-
- uint64_t result = 0ULL;
-
- 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)];
- }
-
-
- uint64_t book_castle_key(const Position& pos) {
-
- uint64_t result = 0ULL;
-
- if (pos.can_castle_kingside(WHITE))
- result ^= Random64[RandomCastle+0];
-
- if (pos.can_castle_queenside(WHITE))
- result ^= Random64[RandomCastle+1];
-
- if (pos.can_castle_kingside(BLACK))
- result ^= Random64[RandomCastle+2];
-
- if (pos.can_castle_queenside(BLACK))
- result ^= Random64[RandomCastle+3];
-
- return result;
- }