X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=0153fa95a41c613cba09a4ff5521dc834da5227d;hp=6c563f72cf1cddf509dfcbb9e2c2f1c145948e88;hb=a7bfaede910c335aecaa4fbcdae6101bcd10f6b7;hpb=6181e01c2a6a40c82c6b76036cc7ba25c952fbe4 diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 6c563f72..0153fa95 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -148,6 +148,10 @@ namespace { #undef S + // Threats weights indexed by sente (side to move has a bigger weight) + const int ConcurrentThreatsWeight[2] = { 3, 15 }; + const int ThreatsWeight[2] = { 249, 267 }; + // Bonus for unstoppable passed pawns const Value UnstoppablePawnValue = Value(0x500); @@ -348,23 +352,23 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) { // Middle-game specific evaluation terms if (phase > PHASE_ENDGAME) { - // Pawn storms in positions with opposite castling - if ( square_file(pos.king_square(WHITE)) >= FILE_E - && square_file(pos.king_square(BLACK)) <= FILE_D) + // Pawn storms in positions with opposite castling + if ( square_file(pos.king_square(WHITE)) >= FILE_E + && square_file(pos.king_square(BLACK)) <= FILE_D) - ei.value += make_score(ei.pi->queenside_storm_value(WHITE) - ei.pi->kingside_storm_value(BLACK), 0); + ei.value += make_score(ei.pi->queenside_storm_value(WHITE) - ei.pi->kingside_storm_value(BLACK), 0); - else if ( square_file(pos.king_square(WHITE)) <= FILE_D - && square_file(pos.king_square(BLACK)) >= FILE_E) + else if ( square_file(pos.king_square(WHITE)) <= FILE_D + && square_file(pos.king_square(BLACK)) >= FILE_E) - ei.value += make_score(ei.pi->kingside_storm_value(WHITE) - ei.pi->queenside_storm_value(BLACK), 0); + ei.value += make_score(ei.pi->kingside_storm_value(WHITE) - ei.pi->queenside_storm_value(BLACK), 0); - // Evaluate space for both sides - if (ei.mi->space_weight() > 0) - { - evaluate_space(pos, ei); - evaluate_space(pos, ei); - } + // Evaluate space for both sides + if (ei.mi->space_weight() > 0) + { + evaluate_space(pos, ei); + evaluate_space(pos, ei); + } } // Mobility @@ -636,6 +640,8 @@ namespace { const Color Them = (Us == WHITE ? BLACK : WHITE); Bitboard b; + Value mg, eg; + int sente, threatCount = 0; Score bonus = make_score(0, 0); // Enemy pieces not defended by a pawn and under our attack @@ -654,9 +660,20 @@ namespace { if (b) for (PieceType pt2 = PAWN; pt2 < KING; pt2++) if (b & pos.pieces(pt2)) + { bonus += ThreatBonus[pt1][pt2]; + threatCount++; + } } - ei.value += Sign[Us] * bonus; + + sente = (Us == pos.side_to_move()); + + // Non linear threat evaluation. Increase threats score according to the + // number of concurrent threats and to the side to move. + mg = (mg_value(bonus) + mg_value(bonus) * ConcurrentThreatsWeight[sente] * threatCount / 256) * ThreatsWeight[sente] / 256; + eg = (eg_value(bonus) + eg_value(bonus) * ConcurrentThreatsWeight[sente] * threatCount / 256) * ThreatsWeight[sente] / 256; + + ei.value += Sign[Us] * make_score(mg, eg); } @@ -820,9 +837,6 @@ namespace { squaresToQueen = squares_in_front_of(Us, s); defendedSquares = squaresToQueen & ei.attacked_by(Us); - // There are no enemy pawns in the pawn's path - assert(!(squaresToQueen & pos.pieces(PAWN, Them))); - // If there is an enemy rook or queen attacking the pawn from behind, // add all X-ray attacks by the rook or queen. Otherwise consider only // the squares in the pawn's path attacked or occupied by the enemy.