-/// Position::see() is a static exchange evaluator: It tries to estimate the
-/// material gain or loss resulting from a move. There are three versions of
-/// this function: One which takes a destination square as input, one takes a
-/// move, and one which takes a 'from' and a 'to' square. The function does
-/// not yet understand promotions captures.
-
-int Position::see_sign(Move m) const {
-
- assert(is_ok(m));
-
- // Early return if SEE cannot be negative because captured piece value
- // is not less then capturing one. Note that king moves always return
- // here because king midgame value is set to 0.
- if (PieceValue[MG][piece_on(to_sq(m))] >= PieceValue[MG][piece_moved(m)])
- return 1;
-
- return see(m);
-}
-
-int Position::see(Move m) const {
-
- Square from, to;
- Bitboard occupied, attackers, stmAttackers;
- int swapList[32], slIndex = 1;
- PieceType captured;
- Color stm;
-
- assert(is_ok(m));
-
- from = from_sq(m);
- to = to_sq(m);
- captured = type_of(piece_on(to));
- occupied = pieces() ^ from;
-
- // Handle en passant moves
- if (type_of(m) == ENPASSANT)
- {
- Square capQq = to - pawn_push(sideToMove);
-
- assert(!captured);
- assert(type_of(piece_on(capQq)) == PAWN);
-
- // 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);