generateMovesForPiece method Null safety

List<Move> generateMovesForPiece(
  1. {required String fromSquare,
  2. bool legal = true}
)

Generate moves for a determined piece Receives the square where the piece is on, in case there is none piece returns empty []

Implementation

List<Move> generateMovesForPiece(
    {required String fromSquare, bool legal = true}) {
  List<Move> moves = [];
  if (get(fromSquare) == null) return moves;
  moves = generateMoves({'legal': legal});
  if (moves.isNotEmpty) {
    moves.removeWhere((element) => element.fromAlgebraic != fromSquare);
  }
  return moves;
}