- rule50++;
-
- if(move_is_castle(m))
- do_castle_move(m);
- else if(move_promotion(m))
- do_promotion_move(m, u);
- else if(move_is_ep(m))
- do_ep_move(m);
- else {
- Color us, them;
- Square from, to;
- PieceType piece, capture;
-
- us = side_to_move();
- them = opposite_color(us);
-
- from = move_from(m);
- to = move_to(m);
-
- assert(color_of_piece_on(from) == us);
- assert(color_of_piece_on(to) == them || piece_on(to) == EMPTY);
-
- piece = type_of_piece_on(from);
- 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];
-
- // If the captured piece was a pawn, update pawn hash key:
- if(capture == PAWN)
- pawnKey ^= zobrist[them][PAWN][to];
-
- // Update incremental scores:
- mgValue -= mg_pst(them, capture, to);
- egValue -= eg_pst(them, capture, to);
-
- // Update material:
- if(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;
-
- // Reset rule 50 counter:
- rule50 = 0;
- }
-
- // Move the piece:
- clear_bit(&(byColorBB[us]), from);
- clear_bit(&(byTypeBB[piece]), from);
- clear_bit(&(byTypeBB[0]), from); // HACK: byTypeBB[0] == occupied squares
- set_bit(&(byColorBB[us]), to);
- set_bit(&(byTypeBB[piece]), to);
- set_bit(&(byTypeBB[0]), to); // HACK: byTypeBB[0] == occupied squares
- board[to] = board[from];
- board[from] = EMPTY;
-
- // Update hash key:
- key ^= zobrist[us][piece][from] ^ zobrist[us][piece][to];
-
- // Update incremental scores:
- mgValue -= mg_pst(us, piece, from);
- mgValue += mg_pst(us, piece, to);
- egValue -= eg_pst(us, piece, from);
- egValue += eg_pst(us, piece, to);
-
- // If the moving piece was a king, update the king square:
- if(piece == KING)
- kingSquare[us] = to;
-
- // If the move was a double pawn push, set the en passant square.
- // This code is a bit ugly right now, and should be cleaned up later.
- // FIXME
- if(epSquare != SQ_NONE) {
- key ^= zobEp[epSquare];
- epSquare = SQ_NONE;
- }
- if(piece == PAWN) {
- if(abs(int(to) - int(from)) == 16) {
- if((us == WHITE && (pawn_attacks(WHITE, from + DELTA_N) &
- pawns(BLACK))) ||
- (us == BLACK && (pawn_attacks(BLACK, from + DELTA_S) &
- pawns(WHITE)))) {
- epSquare = Square((int(from) + int(to)) / 2);
- key ^= zobEp[epSquare];
- }
- }
- // Reset rule 50 draw counter.
- rule50 = 0;
- // Update pawn hash key:
- pawnKey ^= zobrist[us][PAWN][from] ^ zobrist[us][PAWN][to];
- }
-
- // Update piece lists:
- pieceList[us][piece][index[from]] = to;
- index[to] = index[from];
-
- // Update castle rights:
- key ^= zobCastle[castleRights];
- castleRights &= castleRightsMask[from];
- castleRights &= castleRightsMask[to];
- key ^= zobCastle[castleRights];
-
- // Update checkers bitboard:
- checkersBB = EmptyBoardBB;
- Square ksq = king_square(them);
-
- switch(piece) {
-
- case PAWN:
- if(bit_is_set(pawn_attacks(them, ksq), to))
- set_bit(&checkersBB, to);
- if(bit_is_set(dcCandidates, from))
- checkersBB |=
- ((piece_attacks<ROOK>(ksq) & rooks_and_queens(us)) |
- (piece_attacks<BISHOP>(ksq) & bishops_and_queens(us)));
- break;