- // Remove the captured pawn
- occupied ^= capQq;
- captured = PAWN;
- }
- else if (type_of(m) == CASTLE)
- // Castle moves are implemented as king capturing the rook so cannot be
- // handled correctly. Simply return 0 that is always the correct value
- // unless the rook is ends up under attack.
- return 0;
-
- // Find all attackers to the destination square, with the moving piece
- // removed, but possibly an X-ray attacker added behind it.
- attackers = attackers_to(to, occupied);
-
- // If the opponent has no attackers we are finished
- stm = ~color_of(piece_on(from));
- stmAttackers = attackers & pieces(stm);
- if (!stmAttackers)
- return PieceValue[MG][captured];
-
- // The destination square is defended, which makes things rather more
- // difficult to compute. We proceed by building up a "swap list" containing
- // the material gain or loss at each stop in a sequence of captures to the
- // destination square, where the sides alternately capture, and always
- // capture with the least valuable piece. After each capture, we look for
- // new X-ray attacks from behind the capturing piece.
- swapList[0] = PieceValue[MG][captured];
- captured = type_of(piece_on(from));
-
- do {
- assert(slIndex < 32);
-
- // Add the new entry to the swap list
- swapList[slIndex] = -swapList[slIndex - 1] + PieceValue[MG][captured];
- slIndex++;
-
- // Locate and remove from 'occupied' the next least valuable attacker
- captured = next_attacker<PAWN>(byTypeBB, to, stmAttackers, occupied, attackers);
-
- attackers &= occupied; // Remove the just found attacker
- stm = ~stm;
- stmAttackers = attackers & pieces(stm);