- 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) == pawn_of_color(us));
- assert(color_of_piece_on(to) == them || square_is_empty(to));
-
- capture = type_of_piece_on(to);
-
- if(capture) {
- assert(capture != KING);
-
- // Remove captured piece:
- clear_bit(&(byColorBB[them]), to);
- clear_bit(&(byTypeBB[capture]), to);
-
- // Update hash key:
- key ^= zobrist[them][capture][to];
-
- // Update incremental scores:
- mgValue -= mg_pst(them, capture, to);
- egValue -= eg_pst(them, capture, to);
-
- // Update material. Because our move is a promotion, we know that the
- // captured piece is not a pawn.
- assert(capture != PAWN);
- npMaterial[them] -= piece_value_midgame(capture);
-
- // 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);