]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Skip ei.kingZone[] initialization together with king safety
[stockfish] / src / evaluate.cpp
index 86cebecb7efb8ba736d8e818dcc6b31e09cf96dc..0f116a85b7f0f99456ce647f72c53ae7441181f4 100644 (file)
@@ -331,10 +331,8 @@ Value do_evaluate(const Position& pos, Value& margin) {
   bonus +=  evaluate_passed_pawns<WHITE>(pos, ei)
           - evaluate_passed_pawns<BLACK>(pos, ei);
 
-  Phase phase = mi->game_phase();
-
   // Evaluate space for both sides, only in middle-game.
-  if (phase > PHASE_ENDGAME && mi->space_weight() > 0)
+  if (mi->space_weight())
   {
       int s = evaluate_space<WHITE, HasPopCnt>(pos, ei) - evaluate_space<BLACK, HasPopCnt>(pos, ei);
       bonus += apply_weight(make_score(s * mi->space_weight(), 0), Weights[Space]);
@@ -343,6 +341,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
   // Scale winning side if position is more drawish that what it appears
   ScaleFactor sf = eg_value(bonus) > VALUE_ZERO ? mi->scale_factor(pos, WHITE)
                                                 : mi->scale_factor(pos, BLACK);
+  Phase phase = mi->game_phase();
 
   // If we don't already have an unusual scale factor, check for opposite
   // colored bishop endgames, and use a lower scale for those.
@@ -443,11 +442,11 @@ namespace {
     const Color Them = (Us == WHITE ? BLACK : WHITE);
 
     Bitboard b = ei.attackedBy[Them][KING] = pos.attacks_from<KING>(pos.king_square(Them));
-    ei.kingZone[Us] = (b | (Us == WHITE ? b >> 8 : b << 8));
     ei.attackedBy[Us][PAWN] = ei.pi->pawn_attacks(Us);
     ei.updateKingTables[Us] = pos.piece_count(Us, QUEEN) && pos.non_pawn_material(Us) >= QueenValueMidgame + RookValueMidgame;
     if (ei.updateKingTables[Us])
     {
+        ei.kingZone[Us] = (b | (Us == WHITE ? b >> 8 : b << 8));
         b &= ei.attackedBy[Us][PAWN];
         ei.kingAttackersCount[Us] = b ? count_1s<Max15>(b) / 2 : EmptyBoardBB;
         ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = EmptyBoardBB;