moveFromAlgebraic method

Move moveFromAlgebraic(
  1. String alg
)

Create a Move from an algebraic string (e.g. a2a3, g6f3) for a board of this size.

Implementation

Move moveFromAlgebraic(String alg) {
  if (alg[1] == '@') {
    // it's a drop
    int from = HAND;
    int to = squareNumber(alg.substring(2, 4));
    return Move(from: from, to: to, piece: alg[0].toUpperCase());
  }
  int from = squareNumber(alg.substring(0, 2));
  int to = squareNumber(alg.substring(2, 4));

  String? piece;
  int? gatingSquare;
  String? promo;
  List<String> _sections = alg.split('/');
  if (_sections.length > 1) {
    String _gate = _sections.last;
    piece = _gate[0];
    gatingSquare = _gate.length > 2 ? squareNumber(_gate.substring(1, 3)) : from;
  } else {
    promo = (alg.length > 4) ? alg[4] : null;
  }

  return Move(
    from: from,
    to: to,
    promo: promo,
    piece: piece,
    gatingSquare: gatingSquare,
  );
}