X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=ac0bf8cce9cc81571873889c3e5714b670cd0f47;hp=08796159bde5e8cc1860a512c5e541e2dd8df7ee;hb=b508f9561cc2302c129efe8d60f201ff03ee72c8;hpb=020dd69a3512d01c7f189b1aea64fa75c7e1b7cd diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 08796159..ac0bf8cc 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -2,7 +2,7 @@ Stockfish, a UCI chess playing engine derived from Glaurung 2.1 Copyright (C) 2004-2008 Tord Romstad (Glaurung author) Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad - Copyright (C) 2015-2017 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad + Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad Stockfish is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -220,7 +220,6 @@ namespace { const Score WeakQueen = S( 50, 10); const Score CloseEnemies = S( 7, 0); const Score PawnlessFlank = S( 20, 80); - const Score ThreatByHangingPawn = S( 71, 61); const Score ThreatBySafePawn = S(192,175); const Score ThreatByRank = S( 16, 3); const Score Hanging = S( 48, 27); @@ -310,8 +309,8 @@ namespace { while ((s = *pl++) != SQ_NONE) { // Find attacked squares, including x-ray attacks for bishops and rooks - b = Pt == BISHOP ? attacks_bb(s, pos.pieces() ^ pos.pieces(Us, QUEEN)) - : Pt == ROOK ? attacks_bb< ROOK>(s, pos.pieces() ^ pos.pieces(Us, ROOK, QUEEN)) + b = Pt == BISHOP ? attacks_bb(s, pos.pieces() ^ pos.pieces(QUEEN)) + : Pt == ROOK ? attacks_bb< ROOK>(s, pos.pieces() ^ pos.pieces(QUEEN) ^ pos.pieces(Us, ROOK)) : pos.attacks_from(s); if (pos.pinned_pieces(Us) & s) @@ -423,13 +422,11 @@ namespace { Score Evaluation::evaluate_king() { const Color Them = (Us == WHITE ? BLACK : WHITE); - const Direction Up = (Us == WHITE ? NORTH : SOUTH); const Bitboard Camp = (Us == WHITE ? AllSquares ^ Rank6BB ^ Rank7BB ^ Rank8BB : AllSquares ^ Rank1BB ^ Rank2BB ^ Rank3BB); const Square ksq = pos.square(Us); Bitboard weak, b, b1, b2, safe, unsafeChecks; - int kingDanger; // King shelter and enemy pawns storm Score score = pe->king_safety(pos, ksq); @@ -442,7 +439,7 @@ namespace { & ~attackedBy2[Us] & (attackedBy[Us][KING] | attackedBy[Us][QUEEN] | ~attackedBy[Us][ALL_PIECES]); - kingDanger = unsafeChecks = 0; + int kingDanger = unsafeChecks = 0; // Analyse the safe enemy's checks which are possible on next move safe = ~pos.pieces(Them); @@ -478,9 +475,8 @@ namespace { unsafeChecks |= b; // Unsafe or occupied checking squares will also be considered, as long as - // the square is not defended by our pawns or occupied by a blocked pawn. - unsafeChecks &= ~( attackedBy[Us][PAWN] - | (pos.pieces(Them, PAWN) & shift(pos.pieces(PAWN)))); + // the square is in the attacker's mobility area. + unsafeChecks &= mobilityArea[Them]; kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them] + 102 * kingAdjacentZoneAttacksCount[Them] @@ -492,7 +488,11 @@ namespace { // Transform the kingDanger units into a Score, and substract it from the evaluation if (kingDanger > 0) + { + int mobilityDanger = mg_value(mobility[Them] - mobility[Us]); + kingDanger = std::max(0, kingDanger + mobilityDanger); score -= make_score(kingDanger * kingDanger / 4096, kingDanger / 16); + } } // King tropism: firstly, find squares that opponent attacks in our king flank @@ -546,9 +546,6 @@ namespace { safeThreats = (shift(b) | shift(b)) & weak; score += ThreatBySafePawn * popcount(safeThreats); - - if (weak ^ safeThreats) - score += ThreatByHangingPawn; } // Squares strongly protected by the opponent, either because they attack the @@ -894,7 +891,7 @@ namespace { Trace::add(TOTAL, score); } - return (pos.side_to_move() == WHITE ? v : -v) + Eval::Tempo; // Side to move point of view + return pos.side_to_move() == WHITE ? v : -v; // Side to move point of view } } // namespace @@ -906,7 +903,7 @@ Score Eval::Contempt = SCORE_ZERO; Value Eval::evaluate(const Position& pos) { - return Evaluation<>(pos).value(); + return Evaluation<>(pos).value() + Eval::Tempo; } /// trace() is like evaluate(), but instead of returning a value, it returns @@ -917,7 +914,7 @@ std::string Eval::trace(const Position& pos) { std::memset(scores, 0, sizeof(scores)); - Value v = Evaluation(pos).value(); + Value v = Evaluation(pos).value() + Eval::Tempo; v = pos.side_to_move() == WHITE ? v : -v; // White's point of view std::stringstream ss;