getPiecesArray function

List<List<String>> getPiecesArray(
  1. String fen
)

Implementation

List<List<String>> getPiecesArray(String fen) {
  var fenParts = fen.split(' ');
  final lines = fenParts[0].split('/');
  var piecesArray = lines.map((currentLine) {
    var arrayLine = <String>[];
    final elements = currentLine.split('');
    for (var currentElement in elements) {
      if (currentElement.isNumeric) {
        final holesCount = currentElement.codeUnitAt(0) - '0'.codeUnitAt(0);
        for (int j = 0; j < holesCount; j++) {
          arrayLine.add('');
        }
      } else {
        arrayLine.add(currentElement);
      }
    }
    return arrayLine;
  }).toList();

  return piecesArray;
}