- return result;
- }
-
-
- uint64_t book_piece_key(Piece p, Square s) {
- 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;
- }
-
-
- uint64_t book_ep_key(const Position &pos) {
- return (pos.ep_square() == SQ_NONE)?
- 0ULL : Random64[RandomEnPassant + square_file(pos.ep_square())];
- }
-
-
- uint64_t book_color_key(const Position &pos) {
- return (pos.side_to_move() == WHITE)? Random64[RandomTurn] : 0ULL;
- }
-
-
- uint64_t read_integer(FILE *file, int size) {
- uint64_t n = 0ULL;
- int i;
- int b;
-
- assert(file != NULL);
- assert(size > 0 && size <= 8);
-
- for(i = 0; i < size; i++) {
- b = fgetc(file);
- if(b == EOF) {
- std::cerr << "Failed to read " << size << " bytes from book file"
- << std::endl;
- exit(EXIT_FAILURE);
- }
- assert(b >= 0 && b < 256);
- n = (n << 8) | b;
- }
- return n;
- }
-
- uint16_t read_small_integer(FILE *file, int size) {
-
- assert(size > 0 && size <= 5); // 16 bit integer
- uint64_t n = read_integer(file, size);
- assert(n == (uint16_t)n);
- return (uint16_t)n;