rootCount method

int rootCount(
  1. ChessPos pos,
  2. int team
)

获取某个位置的根数

Implementation

int rootCount(ChessPos pos, int team) {
  ChessFen cFen = fen.copy();
  String chess = cFen[pos.y][pos.x];
  if (chess == '0' ||
      (chess.codeUnitAt(0) < ChessFen.colIndexBase && team == 0) ||
      (chess.codeUnitAt(0) >= ChessFen.colIndexBase && team == 1)) {
    cFen[pos.y][pos.x] = team == 0 ? 'p' : 'P';
    cFen.clearFen();
  }

  List<ChessItem> items = cFen.getAll();
  return items
      .where(
        (item) =>
            item.position != pos &&
            item.team == team &&
            ChessRule(cFen)
                .movePoints(item.position, pos)
                .contains(pos.toCode()),
      )
      .length;
}