- // Update material hash key:
- materialKey ^= zobMaterial[them][capture][pieceCount[them][capture]];
-
- // Update piece count:
- pieceCount[them][capture]--;
-
- // Update piece list:
- pieceList[them][capture][index[to]] =
- pieceList[them][capture][pieceCount[them][capture]];
- index[pieceList[them][capture][index[to]]] = index[to];
-
- // Remember the captured piece, in order to be able to undo the move
- // correctly:
- u.capture = capture;
- }
-
- // 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 -= mg_pst(us, PAWN, from);
- mgValue += mg_pst(us, promotion, to);
- egValue -= eg_pst(us, PAWN, from);
- egValue += eg_pst(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];
-
- // Reset rule 50 counter:
- rule50 = 0;
-
- // Update checkers BB:
- checkersBB = attacks_to(king_square(them), us);
-}
-
-
-/// Position::do_ep_move() is a private method used to make an en passant
-/// capture. It is called from the main Position::do_move function. Because
-/// the captured piece is always a pawn, we don't need to pass an UndoInfo
-/// object in which to store the captured piece.
-
-void Position::do_ep_move(Move m) {
- Color us, them;
- Square from, to, capsq;
-
- assert(is_ok());
- assert(move_is_ok(m));
- assert(move_is_ep(m));
-
- us = side_to_move();
- them = opposite_color(us);
-
- // Find from, to and capture squares:
- from = move_from(m);
- to = move_to(m);
- capsq = (us == WHITE)? (to - DELTA_N) : (to - DELTA_S);
-
- assert(to == epSquare);
- assert(relative_rank(us, to) == RANK_6);
- assert(piece_on(to) == EMPTY);
- assert(piece_on(from) == pawn_of_color(us));
- assert(piece_on(capsq) == pawn_of_color(them));
-
- // Remove captured piece:
- clear_bit(&(byColorBB[them]), capsq);
- clear_bit(&(byTypeBB[PAWN]), capsq);
- clear_bit(&(byTypeBB[0]), capsq); // HACK: byTypeBB[0] == occupied squares
- board[capsq] = EMPTY;
-
- // Remove moving piece from source square:
- clear_bit(&(byColorBB[us]), from);
- clear_bit(&(byTypeBB[PAWN]), from);
- clear_bit(&(byTypeBB[0]), from); // HACK: byTypeBB[0] == occupied squares
-
- // Put moving piece on destination square:
- set_bit(&(byColorBB[us]), to);
- set_bit(&(byTypeBB[PAWN]), to);
- set_bit(&(byTypeBB[0]), to); // HACK: byTypeBB[0] == occupied squares
- board[to] = board[from];
- board[from] = EMPTY;
-
- // Update material hash key:
- materialKey ^= zobMaterial[them][PAWN][pieceCount[them][PAWN]];