-int Position::see(Move m, int asymmThreshold) 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);
- swapList[0] = PieceValue[MG][piece_on(to)];
- stm = color_of(piece_on(from));
- occupied = pieces() ^ from;
-
- // Castling moves are implemented as king capturing the rook so cannot be
- // handled correctly. Simply return 0 that is always the correct value
- // unless in the rare case the rook ends up under attack.
- if (type_of(m) == CASTLING)
- return 0;
-
- if (type_of(m) == ENPASSANT)
- {
- occupied ^= to - pawn_push(stm); // Remove the captured pawn
- swapList[0] = PieceValue[MG][PAWN];
- }
-
- // 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) & occupied;
-
- // If the opponent has no attackers we are finished
- stm = ~stm;
- stmAttackers = attackers & pieces(stm);
- if (!stmAttackers)
- return swapList[0];
-
- // 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.
- 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 the next least valuable attacker
- captured = min_attacker<PAWN>(byTypeBB, to, stmAttackers, occupied, attackers);
- stm = ~stm;
- stmAttackers = attackers & pieces(stm);