move_to_san method

String move_to_san(
  1. Move move
)

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

Implementation

String move_to_san(Move move) {
  var output = '';
  final 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 = get_disambiguator(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();
    }
  }

  make_move(move);
  if (in_check) {
    if (in_checkmate) {
      output += '#';
    } else {
      output += '+';
    }
  }
  undo_move();

  return output;
}