- // 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;
+ Color us = pos.side_to_move();
+
+ threatenedByPawn = pos.attacks_by<PAWN>(~us);
+ threatenedByMinor = pos.attacks_by<KNIGHT>(~us) | pos.attacks_by<BISHOP>(~us) | threatenedByPawn;
+ threatenedByRook = pos.attacks_by<ROOK>(~us) | threatenedByMinor;
+
+ // Pieces threatened by pieces of lesser material value
+ threatenedPieces = (pos.pieces(us, QUEEN) & threatenedByRook)
+ | (pos.pieces(us, ROOK) & threatenedByMinor)
+ | (pos.pieces(us, KNIGHT, BISHOP) & threatenedByPawn);