lastMoveTo property
Position?
get
lastMoveTo
Returns the "to Position square" where a ChessPiece was moved, deduced by comparing the second last and last FEN strings.
Implementation
Position? get lastMoveTo {
if (history.length < 2) return null;
String previousFen = history[history.length - 2];
String currentFen = history.last;
List<List<ChessPiece?>> prevBoard = _decodeBoard(previousFen);
List<List<ChessPiece?>> currBoard = _decodeBoard(currentFen);
for (int row = 0; row < 8; row++) {
for (int col = 0; col < 8; col++) {
// If a square was empty and now holds a piece,
// that square is the destination.
if (prevBoard[row][col] == null && currBoard[row][col] != null) {
return Position(row: row, col: col);
}
}
}
return null;
}