getPieceMap function

Map<String, Piece> getPieceMap(
  1. String fen
)

Implementation

Map<String, Piece> getPieceMap(String fen) {
  final chess = ch.Chess.fromFEN(fen);
  final squares = ch.Chess.SQUARES.keys.toList();
  final map = Map<String, Piece>();
  squares.forEach((square) {
    final piece = chess.get(square);

    if (piece != null) {
      map[square] = Piece(
        PieceType.fromString(piece.type.toString()),
        piece.color == ch.Color.WHITE ? Color.WHITE : Color.BLACK,
      );
    }
  });
  return map;
}