moveToSan method

String moveToSan(
  1. Move move
)

Convert a move from 0x88 coordinates to Standard Algebraic Notation(SAN)

Implementation

String moveToSan(Move move) {
  String output = '';
  int flags = move.flags;
  if ((flags & BITS_KSIDE_CASTLE) != 0) {
    output = 'O-O';
  } else if ((flags & BITS_QSIDE_CASTLE) != 0) {
    output = 'O-O-O';
  } else {
    var disambiguator = getDisambiguator(move);

    if (move.piece != PAWN) {
      output += move.piece.toUpperCase() + disambiguator;
    }

    if ((flags & (BITS_CAPTURE | BITS_EP_CAPTURE)) != 0) {
      if (move.piece == PAWN) {
        output += move.fromAlgebraic[0];
      }
      output += 'x';
    }

    output += move.toAlgebraic;

    if ((flags & BITS_PROMOTION) != 0) {
      output += '=' + move.promotion!.toUpperCase();
    }
  }

  makeMove(move);
  if (inCheck) {
    if (inCheckmate) {
      output += '#';
    } else {
      output += '+';
    }
  }
  undoMove();

  return output;
}