initFEN method
initializes the board with the given FEN string.
Implementation
void initFEN(String fen) {
board = _emptyBoard;
List<String> parts = fen.split(" ");
List<String> rows = parts[0].split("/");
// Determine turn from FEN.
turn = (parts[1] == "w") ? PieceColor.white : PieceColor.black;
// En-passant target square (if any).
if (parts[3] != "-") {
String targetSquare = parts[3];
int col = targetSquare.codeUnitAt(0) - 'a'.codeUnitAt(0);
int row = 8 - int.parse(targetSquare[1]);
enPassantTarget = Position(row: row, col: col);
} else {
enPassantTarget = null;
}
halfMoveClock = int.tryParse(parts[4]) ?? 0; // Halfmove clock from FEN
fullMoveNumber = int.tryParse(parts[5]) ?? 1; // Fullmove number from FEN
// Here we assume the FEN rows correspond directly to board rows (0 to 7).
for (int row = 0; row < 8; row++) {
int col = 0;
String fenRow = rows[row]; // no reversal
for (int i = 0; i < fenRow.length; i++) {
String charAt = fenRow[i];
if (RegExp(r'[1-8]').hasMatch(charAt)) {
col += int.parse(charAt);
} else {
board[row][col] = ChessBoardInterface.getPieceFromChar(charAt);
col++;
}
}
}
}