hasInsufficientMaterial method

bool hasInsufficientMaterial(
  1. Side side
)

Tests if a Side has insufficient winning material.

Implementation

bool hasInsufficientMaterial(Side side) {
  if (board.bySide(side).isIntersected(board.pawns | board.rooksAndQueens)) {
    return false;
  }
  if (board.bySide(side).isIntersected(board.knights)) {
    return board.bySide(side).size <= 2 &&
        board
            .bySide(side.opposite)
            .diff(board.kings)
            .diff(board.queens)
            .isEmpty;
  }
  if (board.bySide(side).isIntersected(board.bishops)) {
    final sameColor = !board.bishops.isIntersected(SquareSet.darkSquares) ||
        !board.bishops.isIntersected(SquareSet.lightSquares);
    return sameColor && board.pawns.isEmpty && board.knights.isEmpty;
  }
  return true;
}