- // Undo null move, if necessary
- if (c != stm)
- undo_null_move();
-
- return result;
-}
-
-
-/// Position::init_zobrist() is a static member function which initializes the
-/// various arrays used to compute hash keys.
-
-void Position::init_zobrist() {
-
- for (int i = 0; i < 2; i++)
- for (int j = 0; j < 8; j++)
- for (int k = 0; k < 64; k++)
- zobrist[i][j][k] = Key(genrand_int64());
-
- for (int i = 0; i < 64; i++)
- zobEp[i] = Key(genrand_int64());
-
- for (int i = 0; i < 16; i++)
- zobCastle[i] = genrand_int64();
-
- zobSideToMove = genrand_int64();
- zobExclusion = genrand_int64();
-}
-
-
-/// Position::init_piece_square_tables() initializes the piece square tables.
-/// This is a two-step operation: First, the white halves of the tables are
-/// copied from the MgPST[][] and EgPST[][] arrays, with a small random number
-/// added to each entry if the "Randomness" UCI parameter is non-zero.
-/// Second, the black halves of the tables are initialized by mirroring
-/// and changing the sign of the corresponding white scores.
-
-void Position::init_piece_square_tables() {
-
- int r = get_option_value_int("Randomness"), i;
- for (Square s = SQ_A1; s <= SQ_H8; s++)
- for (Piece p = WP; p <= WK; p++)
- {
- i = (r == 0)? 0 : (genrand_int32() % (r*2) - r);
- PieceSquareTable[p][s] = make_score(MgPST[p][s] + i, EgPST[p][s] + i);
- }
-
- for (Square s = SQ_A1; s <= SQ_H8; s++)
- for (Piece p = BP; p <= BK; p++)
- PieceSquareTable[p][s] = -PieceSquareTable[p-8][flip_square(s)];
-}
-
-
-/// Position::flipped_copy() makes a copy of the input position, but with
-/// the white and black sides reversed. This is only useful for debugging,
-/// especially for finding evaluation symmetry bugs.
-
-void Position::flipped_copy(const Position& pos) {
-
- assert(pos.is_ok());
-
- clear();
-
- // Board
- for (Square s = SQ_A1; s <= SQ_H8; s++)
- if (!pos.square_is_empty(s))
- put_piece(Piece(int(pos.piece_on(s)) ^ 8), flip_square(s));
-
- // Side to move
- sideToMove = opposite_color(pos.side_to_move());
-
- // Castling rights
- if (pos.can_castle_kingside(WHITE)) allow_oo(BLACK);
- if (pos.can_castle_queenside(WHITE)) allow_ooo(BLACK);
- if (pos.can_castle_kingside(BLACK)) allow_oo(WHITE);
- if (pos.can_castle_queenside(BLACK)) allow_ooo(WHITE);
-
- initialKFile = pos.initialKFile;
- initialKRFile = pos.initialKRFile;
- initialQRFile = pos.initialQRFile;