- for (auto& m : *this)
- m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
- + (*contHistory[0])[pos.moved_piece(m)][to_sq(m)]
- + (*contHistory[1])[pos.moved_piece(m)][to_sq(m)]
- + (*contHistory[3])[pos.moved_piece(m)][to_sq(m)];
-}
+ static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type");
+
+ Bitboard threatened, threatenedByPawn, threatenedByMinor, threatenedByRook;
+ if constexpr (Type == QUIETS)
+ {
+ // squares threatened by pawns
+ threatenedByPawn = pos.side_to_move() == WHITE ? threatsByPawn<BLACK>(pos) : threatsByPawn<WHITE>(pos);
+ // squares threatened by minors or pawns
+ threatenedByMinor = pos.side_to_move() == WHITE ? threatsByMinor<BLACK>(pos) : threatsByMinor<WHITE>(pos);
+ threatenedByMinor |= threatenedByPawn;
+ // squares threatened by rooks, minors or pawns
+ threatenedByRook = pos.side_to_move() == WHITE ? threatsByRook<BLACK>(pos) : threatsByRook<WHITE>(pos);
+ threatenedByRook |= threatenedByMinor;
+
+ // pieces threatened by pieces of lesser material value
+ threatened = pos.side_to_move() == WHITE ? ((pos.pieces(WHITE, QUEEN) & threatenedByRook) |
+ (pos.pieces(WHITE, ROOK) & threatenedByMinor) |
+ (pos.pieces(WHITE, KNIGHT, BISHOP) & threatenedByPawn))
+ : ((pos.pieces(BLACK, QUEEN) & threatenedByRook) |
+ (pos.pieces(BLACK, ROOK) & threatenedByMinor) |
+ (pos.pieces(BLACK, KNIGHT, BISHOP) & threatenedByPawn));
+ }
+ else
+ {
+ // Silence unused variable warning
+ (void) threatened;
+ (void) threatenedByPawn;
+ (void) threatenedByMinor;
+ (void) threatenedByRook;
+ }