toAlgebraic method

String toAlgebraic(
  1. Move move
)

Returns the algebraic representation of move, with respect to the board size.

Implementation

String toAlgebraic(Move move) {
  if (move is PassMove) return move.algebraic();
  if (move is DropMove) {
    return '${variant.pieces[move.piece].symbol.toLowerCase()}${move.algebraic(size)}';
  }
  if (move is GatingMove) {
    String alg = toAlgebraic(move.child);
    if (variant.gatingMode == GatingMode.fixed) {
      return alg;
    }
    alg = '$alg/${variant.pieces[move.dropPiece].symbol.toLowerCase()}';
    if (move.child.castling) {
      String dropSq = move.dropOnRookSquare
          ? size.squareName(move.child.castlingPieceSquare!)
          : size.squareName(move.from);
      alg = '$alg$dropSq';
    }
    return alg;
  }
  if (move is! StandardMove) return '';
  String alg = move.algebraic(
    size: size,
    useRookForCastling: variant.castlingOptions.useRookAsTarget,
  );
  if (move.promotion) {
    alg = '$alg${variant.pieces[move.promoPiece!].symbol.toLowerCase()}';
  }
  if (move.from == Bishop.hand) {
    alg = '${variant.pieces[move.dropPiece!].symbol.toLowerCase()}$alg';
  }
  return alg;
}