X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=e167bb6994f788ec4a81ae12b236d34b78d371c8;hp=86cebecb7efb8ba736d8e818dcc6b31e09cf96dc;hb=85a7456bd7e8a1a01cdbfa8f4b6fb563d15a37c6;hpb=d4876dc96395f5592bfbc25b2eca2360db0655e6 diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 86cebecb..e167bb69 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -45,11 +45,6 @@ namespace { // Pointer to pawn hash table entry PawnInfo* pi; - // updateKingTables[color] is set to true if we have enough material - // to trigger the opponent's king safety calculation. When is false we - // skip the time consuming update of the king attackers tables. - bool updateKingTables[2]; - // attackedBy[color][piece type] is a bitboard representing all squares // attacked by a given color and piece type, attackedBy[color][0] contains // all squares attacked by the given color. @@ -246,7 +241,7 @@ namespace { template Score evaluate_passed_pawns(const Position& pos, EvalInfo& ei); - Score apply_weight(Score v, Score weight); + inline Score apply_weight(Score v, Score weight); Value scale_by_game_phase(const Score& v, Phase ph, ScaleFactor sf); Score weight_option(const std::string& mgOpt, const std::string& egOpt, Score internalWeight); void init_safety(); @@ -331,18 +326,17 @@ Value do_evaluate(const Position& pos, Value& margin) { bonus += evaluate_passed_pawns(pos, ei) - evaluate_passed_pawns(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(pos, ei) - evaluate_space(pos, ei); bonus += apply_weight(make_score(s * mi->space_weight(), 0), Weights[Space]); } // Scale winning side if position is more drawish that what it appears - ScaleFactor sf = eg_value(bonus) > VALUE_ZERO ? mi->scale_factor(pos, WHITE) + ScaleFactor sf = eg_value(bonus) > VALUE_DRAW ? 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,15 +437,18 @@ namespace { const Color Them = (Us == WHITE ? BLACK : WHITE); Bitboard b = ei.attackedBy[Them][KING] = pos.attacks_from(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]) + + // Init king safety tables only if we are going to use them + if ( pos.piece_count(Us, QUEEN) + && pos.non_pawn_material(Us) >= QueenValueMidgame + RookValueMidgame) { + ei.kingZone[Us] = (b | (Us == WHITE ? b >> 8 : b << 8)); b &= ei.attackedBy[Us][PAWN]; - ei.kingAttackersCount[Us] = b ? count_1s(b) / 2 : EmptyBoardBB; - ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = EmptyBoardBB; - } + ei.kingAttackersCount[Us] = b ? count_1s(b) / 2 : 0; + ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = 0; + } else + ei.kingZone[Us] = ei.kingAttackersCount[Us] = 0; } @@ -515,7 +512,7 @@ namespace { ei.attackedBy[Us][Piece] |= b; // King attacks - if (ei.updateKingTables[Us] && (b & ei.kingZone[Us])) + if (b & ei.kingZone[Us]) { ei.kingAttackersCount[Us]++; ei.kingAttackersWeight[Us] += KingAttackWeights[Piece]; @@ -667,8 +664,7 @@ namespace { // King safety. This is quite complicated, and is almost certainly far // from optimally tuned. - if ( ei.updateKingTables[Them] - && ei.kingAttackersCount[Them] >= 2 + if ( ei.kingAttackersCount[Them] >= 2 && ei.kingAdjacentZoneAttacksCount[Them]) { // Find the attacked squares around the king which has no defenders