- st->mgValue -= pst<MidGame>(us, KING, kfrom);
- st->mgValue += pst<MidGame>(us, KING, kto);
- st->egValue -= pst<EndGame>(us, KING, kfrom);
- st->egValue += pst<EndGame>(us, KING, kto);
- st->mgValue -= pst<MidGame>(us, ROOK, rfrom);
- st->mgValue += pst<MidGame>(us, ROOK, rto);
- st->egValue -= pst<EndGame>(us, ROOK, rfrom);
- st->egValue += pst<EndGame>(us, ROOK, rto);
-
- // Update hash key
- st->key ^= zobrist[us][KING][kfrom] ^ zobrist[us][KING][kto];
- st->key ^= zobrist[us][ROOK][rfrom] ^ zobrist[us][ROOK][rto];
-
- // Clear en passant square
- if (st->epSquare != SQ_NONE)
- {
- st->key ^= zobEp[st->epSquare];
- st->epSquare = SQ_NONE;
- }
-
- // Update castling rights
- st->key ^= zobCastle[st->castleRights];
- st->castleRights &= castleRightsMask[kfrom];
- st->key ^= zobCastle[st->castleRights];
-
- // Reset rule 50 counter
- st->rule50 = 0;
-
- // Update checkers BB
- st->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.
-
-void Position::do_promotion_move(Move m) {
-
- Color us, them;
- Square from, to;
- PieceType 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));
-
- st->capture = type_of_piece_on(to);
-
- if (st->capture)
- do_capture_move(st->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
- st->key ^= zobrist[us][PAWN][from] ^ zobrist[us][promotion][to];
-
- // Update pawn hash key
- st->pawnKey ^= zobrist[us][PAWN][from];
-
- // Update material key
- st->materialKey ^= zobMaterial[us][PAWN][pieceCount[us][PAWN]];
- st->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
- st->mgValue -= pst<MidGame>(us, PAWN, from);
- st->mgValue += pst<MidGame>(us, promotion, to);
- st->egValue -= pst<EndGame>(us, PAWN, from);
- st->egValue += pst<EndGame>(us, promotion, to);