bestPromo method

Move? bestPromo(
  1. List<String> pieceHierarchy, [
  2. bool strict = false
])

Gets the best promotion move according to pieceHierarchy. Returns null if no appropriate move is found. If strict is true, pieces outside of pieceHierarchy won't be considered.

Implementation

Move? bestPromo(List<String> pieceHierarchy, [bool strict = false]) {
  final promos = promoMoves;
  for (String p in pieceHierarchy) {
    final m = promos
        .firstWhereOrNull((e) => e.promo?.toLowerCase() == p.toLowerCase());
    if (m != null) return m;
  }
  return (promos.isNotEmpty && !strict) ? promos.first : null;
}