see method

int see(
  1. int move
)

Static Exchange Evaluation: the material a capture move wins or loses after the full sequence of optimal recaptures on the target square, in centipawns from the moving side's view. Negative means a losing capture.

Implementation

int see(int move) {
  final to = moveTo(move);
  final from = moveFrom(move);
  var occ = occAll;
  int targetType;
  if (moveIsEnPassant(move)) {
    targetType = pawn;
    final capSq = turn == white ? to - 8 : to + 8;
    occ ^= 1 << capSq; // remove ep-captured pawn so x-rays are correct
  } else {
    final t = mailbox[to];
    if (t == -1) return 0; // not a capture
    targetType = t;
  }

  final gain = List<int>.filled(32, 0);
  gain[0] = _seeValues[targetType];
  var attackerType = mailbox[from];
  var fromBit = 1 << from;
  var side = turn;
  var d = 0;

  // Run the full swap sequence (no early pruning — it's subtle and SEE
  // sequences on one square are short, so correctness wins).
  while (true) {
    d++;
    gain[d] = _seeValues[attackerType] - gain[d - 1];
    occ ^= fromBit; // the attacker that just captured leaves the board
    side ^= 1;
    final attackers = _attackersTo(to, occ) & occ;
    final sq = _leastValuableAttacker(attackers, side);
    if (sq < 0) break;
    fromBit = 1 << sq;
    attackerType = mailbox[sq];
  }
  while (--d > 0) {
    gain[d - 1] = -(-gain[d - 1] > gain[d] ? -gain[d - 1] : gain[d]);
  }
  return gain[0];
}