-/// 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;
-
- for (Square sq = SQ_A1; sq <= SQ_H8; sq++)
- castleRightsMask[sq] = ALL_CASTLES;
-
- castleRightsMask[make_square(initialKFile, RANK_1)] ^= (WHITE_OO | WHITE_OOO);
- castleRightsMask[make_square(initialKFile, RANK_8)] ^= (BLACK_OO | BLACK_OOO);
- castleRightsMask[make_square(initialKRFile, RANK_1)] ^= WHITE_OO;
- castleRightsMask[make_square(initialKRFile, RANK_8)] ^= BLACK_OO;
- castleRightsMask[make_square(initialQRFile, RANK_1)] ^= WHITE_OOO;
- castleRightsMask[make_square(initialQRFile, RANK_8)] ^= BLACK_OOO;
-
- // En passant square
- if (pos.st->epSquare != SQ_NONE)
- st->epSquare = flip_square(pos.st->epSquare);
-
- // Checkers
- find_checkers();
-
- // Hash keys
- st->key = compute_key();
- st->pawnKey = compute_pawn_key();
- st->materialKey = compute_material_key();
-
- // Incremental scores
- st->value = compute_value();
-
- // Material
- st->npMaterial[WHITE] = compute_non_pawn_material(WHITE);
- st->npMaterial[BLACK] = compute_non_pawn_material(BLACK);
-
- assert(is_ok());
-}
-
-
-/// Position::is_ok() performs some consitency checks for the position object.