- key ^= zobCastle[castleRights];
- castleRights &= castleRightsMask[kfrom];
- key ^= zobCastle[castleRights];
-
- // Reset rule 50 counter
- rule50 = 0;
-
- // Update checkers BB
- checkersBB = attacks_to(king_square(them), us);
-}
-
-
-/// Position::do_promotion_move() is a private method used to make a promotion
-/// move. It is called from the main Position::do_move function. The
-/// UndoInfo object, which has been initialized in Position::do_move, is
-/// used to store the captured piece (if any).
-
-void Position::do_promotion_move(Move m) {
-
- Color us, them;
- Square from, to;
- PieceType capture, promotion;
-
- assert(is_ok());
- assert(move_is_ok(m));
- assert(move_promotion(m));
-
- us = side_to_move();
- them = opposite_color(us);
- from = move_from(m);
- to = move_to(m);
-
- assert(relative_rank(us, to) == RANK_8);
- assert(piece_on(from) == piece_of_color_and_type(us, PAWN));
- assert(color_of_piece_on(to) == them || square_is_empty(to));
-
- capture = type_of_piece_on(to);
-
- if (capture)
- {
- previous->capture = capture;
- do_capture_move(m, capture, them, to);
- }
-
- // Remove pawn
- clear_bit(&(byColorBB[us]), from);
- clear_bit(&(byTypeBB[PAWN]), from);
- clear_bit(&(byTypeBB[0]), from); // HACK: byTypeBB[0] == occupied squares
- board[from] = EMPTY;
-
- // Insert promoted piece
- promotion = move_promotion(m);
- assert(promotion >= KNIGHT && promotion <= QUEEN);
- set_bit(&(byColorBB[us]), to);
- set_bit(&(byTypeBB[promotion]), to);
- set_bit(&(byTypeBB[0]), to); // HACK: byTypeBB[0] == occupied squares
- board[to] = piece_of_color_and_type(us, promotion);
-
- // Update hash key
- key ^= zobrist[us][PAWN][from] ^ zobrist[us][promotion][to];
-
- // Update pawn hash key
- pawnKey ^= zobrist[us][PAWN][from];
-
- // Update material key
- materialKey ^= zobMaterial[us][PAWN][pieceCount[us][PAWN]];
- materialKey ^= zobMaterial[us][promotion][pieceCount[us][promotion]+1];
-
- // Update piece counts
- pieceCount[us][PAWN]--;
- pieceCount[us][promotion]++;
-
- // Update piece lists
- pieceList[us][PAWN][index[from]] = pieceList[us][PAWN][pieceCount[us][PAWN]];
- index[pieceList[us][PAWN][index[from]]] = index[from];
- pieceList[us][promotion][pieceCount[us][promotion] - 1] = to;
- index[to] = pieceCount[us][promotion] - 1;
-
- // Update incremental scores
- mgValue -= pst<MidGame>(us, PAWN, from);
- mgValue += pst<MidGame>(us, promotion, to);
- egValue -= pst<EndGame>(us, PAWN, from);
- egValue += pst<EndGame>(us, promotion, to);
-
- // Update material
- npMaterial[us] += piece_value_midgame(promotion);
-
- // Clear the en passant square
- if (epSquare != SQ_NONE)
- {
- key ^= zobEp[epSquare];
- epSquare = SQ_NONE;
- }
-
- // Update castle rights
- key ^= zobCastle[castleRights];
- castleRights &= castleRightsMask[to];
- key ^= zobCastle[castleRights];