- Color us = side_to_move();
- Color them = opposite_color(us);
- Square from = move_from(m);
- Square to = move_to(m);
-
- assert(color_of_piece_on(from) == us);
- assert(color_of_piece_on(to) == them || piece_on(to) == EMPTY);
-
- PieceType piece = type_of_piece_on(from);
-
- st.capture = type_of_piece_on(to);
-
- if (st.capture)
- {
- u.capture = st.capture;
- do_capture_move(m, st.capture, them, to);
- }
-
- // 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
- st.key ^= zobrist[us][piece][from] ^ zobrist[us][piece][to];
-
- // Update incremental scores
- st.mgValue -= pst<MidGame>(us, piece, from);
- st.mgValue += pst<MidGame>(us, piece, to);
- st.egValue -= pst<EndGame>(us, piece, from);
- st.egValue += pst<EndGame>(us, piece, to);
-
- // If the moving piece was a king, update the king square
- if (piece == KING)
- kingSquare[us] = to;
-
- // Reset en passant square
- if (st.epSquare != SQ_NONE)
- {
- st.key ^= zobEp[st.epSquare];
- st.epSquare = SQ_NONE;
- }
-
- // If the moving piece was a pawn do some special extra work
- if (piece == PAWN)
- {
- // Reset rule 50 draw counter
- st.rule50 = 0;
-
- // Update pawn hash key
- st.pawnKey ^= zobrist[us][PAWN][from] ^ zobrist[us][PAWN][to];
-
- // Set en passant square, only if moved pawn can be captured
- 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))))
- {
- st.epSquare = Square((int(from) + int(to)) / 2);
- st.key ^= zobEp[st.epSquare];
- }
- }
- }
-
- // Update piece lists
- pieceList[us][piece][index[from]] = to;
- index[to] = index[from];
-
- // Update castle rights
- st.key ^= zobCastle[st.castleRights];
- st.castleRights &= castleRightsMask[from];
- st.castleRights &= castleRightsMask[to];
- st.key ^= zobCastle[st.castleRights];
-
- // Update checkers bitboard, piece must be already moved
- st.checkersBB = EmptyBoardBB;
- Square ksq = king_square(them);
- switch (piece)
- {
- case PAWN: update_checkers<PAWN>(&st.checkersBB, ksq, from, to, oldDcCandidates); break;
- case KNIGHT: update_checkers<KNIGHT>(&st.checkersBB, ksq, from, to, oldDcCandidates); break;
- case BISHOP: update_checkers<BISHOP>(&st.checkersBB, ksq, from, to, oldDcCandidates); break;
- case ROOK: update_checkers<ROOK>(&st.checkersBB, ksq, from, to, oldDcCandidates); break;
- case QUEEN: update_checkers<QUEEN>(&st.checkersBB, ksq, from, to, oldDcCandidates); break;
- case KING: update_checkers<KING>(&st.checkersBB, ksq, from, to, oldDcCandidates); break;
- default: assert(false); break;
- }
- }