X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=c2f025fccd87047034fea47ad8d8984b27b1b2ad;hp=e861f5f032e95d80f54bb4137447e617686b338b;hb=653c0527a70c3a134983519a1cf13ffbde120205;hpb=79bcb2ca54aa72bd9e3d1ba1ed1dcb2a4ddf14c9 diff --git a/src/evaluate.cpp b/src/evaluate.cpp index e861f5f0..c2f025fc 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -642,31 +642,19 @@ Value do_evaluate(const Position& pos, Value& margin) { score += RookHalfOpenFileBonus; } - // Penalize rooks which are trapped inside a king. Penalize more if - // king has lost right to castle. if (mob > 6 || ei.pi->file_is_half_open(Us, f)) continue; ksq = pos.king_square(Us); - if ( file_of(ksq) >= FILE_E - && file_of(s) > file_of(ksq) - && (relative_rank(Us, ksq) == RANK_1 || rank_of(ksq) == rank_of(s))) - { - // Is there a half-open file between the king and the edge of the board? - if (!ei.pi->has_open_file_to_right(Us, file_of(ksq))) - score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2 - : (TrappedRookPenalty - mob * 16), 0); - } - else if ( file_of(ksq) <= FILE_D - && file_of(s) < file_of(ksq) - && (relative_rank(Us, ksq) == RANK_1 || rank_of(ksq) == rank_of(s))) - { - // Is there a half-open file between the king and the edge of the board? - if (!ei.pi->has_open_file_to_left(Us, file_of(ksq))) - score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2 - : (TrappedRookPenalty - mob * 16), 0); - } + // Penalize rooks which are trapped inside a king. Penalize more if + // king has lost right to castle. + if ( ((file_of(ksq) < FILE_E) == (file_of(s) < file_of(ksq))) + && rank_of(ksq) == rank_of(s) + && relative_rank(Us, ksq) == RANK_1 + && !ei.pi->has_open_file_on_side(Us, file_of(ksq), file_of(ksq) < FILE_E)) + score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2 + : (TrappedRookPenalty - mob * 16), 0); } } @@ -730,7 +718,7 @@ Value do_evaluate(const Position& pos, Value& margin) { Score score = mobility = SCORE_ZERO; // Do not include in mobility squares protected by enemy pawns or occupied by our pieces - const Bitboard mobilityArea = ~(ei.attackedBy[Them][PAWN] | pos.pieces(Us)); + const Bitboard mobilityArea = ~(ei.attackedBy[Them][PAWN] | pos.pieces(Us, PAWN, KING)); score += evaluate_pieces(pos, ei, mobility, mobilityArea); score += evaluate_pieces(pos, ei, mobility, mobilityArea); @@ -912,16 +900,30 @@ Value do_evaluate(const Position& pos, Value& margin) { else unsafeSquares = squaresToQueen & (ei.attackedBy[Them][ALL_PIECES] | pos.pieces(Them)); - // If there aren't enemy attacks or pieces along the path to queen give - // huge bonus. Even bigger if we protect the pawn's path. - if (!unsafeSquares) - ebonus += Value(rr * (squaresToQueen == defendedSquares ? 17 : 15)); - else - // OK, there are enemy attacks or pieces (but not pawns). Are those - // squares which are attacked by the enemy also attacked by us ? - // If yes, big bonus (but smaller than when there are no enemy attacks), - // if no, somewhat smaller bonus. - ebonus += Value(rr * ((unsafeSquares & defendedSquares) == unsafeSquares ? 13 : 8)); + // Default bonus for the empty square in front + int bonusMultiplier = 3; + + if ((defendedSquares & SquareBB[blockSq]) != 0) + { + // Defending the square in front + bonusMultiplier += 2; + if ((unsafeSquares & defendedSquares) == unsafeSquares) + // Defending all the attacked squares + // bigger bonus if we are defending everything + bonusMultiplier += (squaresToQueen == defendedSquares) ? 4 : 2; + } + + if ((unsafeSquares & SquareBB[blockSq]) == 0) + { + // The square infront isn't attacked + bonusMultiplier += 6; + if (!unsafeSquares) + bonusMultiplier += 6; + } + + Value bonus = Value(rr * bonusMultiplier); + ebonus += bonus; + mbonus += bonus; } } // rr != 0