getCheckMoves method

List<String> getCheckMoves(
  1. int team
)

获取某方所有的将军招法

Implementation

List<String> getCheckMoves(int team) {
  List<String> moves = [];
  // 对方老将
  ChessPos? kPos = fen.find(team == 0 ? 'k' : 'K');
  if (kPos == null) {
    // 老将没了
    return moves;
  }
  List<ChessItem> pieces = fen.getAll();

  for (var item in pieces) {
    if (item.team == team) {
      // 这里传入目标位置,返回的可行点有针对性
      List<String> points = movePoints(item.position);
      // 挪子后其它子可将军
      for (var point in points) {
        ChessRule nRule = ChessRule(fen.copy());
        nRule.fen.move(item.position.toCode() + point);
        if (nRule.isCheck(team == 0 ? 1 : 0)) {
          moves.add(item.position.toCode() + point);
        }
      }
    }
  }
  return moves;
}