canParryKill method

bool canParryKill(
  1. int team
)

Can the deadlock be solved 是否可以解杀

Implementation

bool canParryKill(int team) {
  ChessPos? kPos = fen.find(team == 0 ? 'K' : 'k');
  if (kPos == null) {
    // 老将没了
    return false;
  }

  List<ChessItem> pieces = fen.getAll();

  return pieces.any((item) {
    if (item.team == team) {
      List<String> points = movePoints(item.position);
      return points.any((point) {
        ChessRule rule = ChessRule(fen.copy());
        rule.fen.move(item.position.toCode() + point);
        if (rule.isKingMeet(team)) {
          return false;
        }
        if (rule.isCheck(team)) {
          return false;
        }
        // print('$item $point');
        return true;
      });
    }
    return false;
  });
}