- int shelter = 0, sign = Sign[us];
- Square s = p.king_square(us);
+ evaluate_pieces<KNIGHT, Us, HasPopCnt>(pos, ei);
+ evaluate_pieces<BISHOP, Us, HasPopCnt>(pos, ei);
+ evaluate_pieces<ROOK, Us, HasPopCnt>(pos, ei);
+ evaluate_pieces<QUEEN, Us, HasPopCnt>(pos, ei);
+
+ // Sum up all attacked squares
+ ei.attackedBy[Us][0] = ei.attackedBy[Us][PAWN] | ei.attackedBy[Us][KNIGHT]
+ | ei.attackedBy[Us][BISHOP] | ei.attackedBy[Us][ROOK]
+ | ei.attackedBy[Us][QUEEN] | ei.attackedBy[Us][KING];
+ }
+
+
+ // evaluate_king<>() assigns bonuses and penalties to a king of a given color
+
+ template<Color Us, bool HasPopCnt>
+ void evaluate_king(const Position& pos, EvalInfo& ei) {
+
+ const Color Them = (Us == WHITE ? BLACK : WHITE);
+ const Square s = pos.king_square(Us);
+ int shelter = 0;