X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=e53af1037e523bc101eece2152fcbf56874a2f20;hp=28fd8341e8d8cfad2aba6ac7c694d1eee525b002;hb=e3b54235ad2407d3f066dd7a9e1f6bb0fa14320b;hpb=be641e881fdfdf3354453381f832fe7822e7c731 diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 28fd8341..e53af103 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -119,8 +119,8 @@ namespace { { S(-17,-33), S(-11,-16), S(-5, 0), S( 1, 16), S( 7, 32), S(13, 48), // Rooks S( 18, 64), S( 22, 80), S(26, 96), S(29,109), S(31,115), S(33,119), S( 35,122), S( 36,123), S(37,124) }, - { S(-12,-20), S( -8,-13), S(-5, -7), S(-2, -1), S( 1, 5), S( 4, 11), // Queens - S( 7, 17), S( 10, 23), S(13, 29), S(16, 34), S(18, 38), S(20, 40), + { S(-12,-20), S( -8,-13), S(-5, -7), S( 0, 0), S( 6, 10), S(11, 19), // Queens + S( 13, 29), S( 18, 38), S(20, 40), S(21, 41), S(22, 41), S(22, 41), S( 22, 41), S( 23, 41), S(24, 41), S(25, 41), S(25, 41), S(25, 41), S( 25, 41), S( 25, 41), S(25, 41), S(25, 41), S(25, 41), S(25, 41), S( 25, 41), S( 25, 41), S(25, 41), S(25, 41) } @@ -171,6 +171,7 @@ namespace { const Score UndefendedMinor = make_score(25, 10); const Score TrappedRook = make_score(90, 0); const Score Unstoppable = make_score( 0, 20); + const Score LowMobPenalty = make_score(40, 20); // Penalty for a bishop on a1/h1 (a8/h8 for black) which is trapped by // a friendly pawn on b2/g2 (b7/g7 for black). This can obviously only @@ -186,6 +187,8 @@ namespace { (FileCBB | FileDBB | FileEBB | FileFBB) & (Rank7BB | Rank6BB | Rank5BB) }; + const Bitboard EdgeBB = Rank1BB | Rank8BB | FileABB | FileHBB; + // King danger constants and variables. The king danger scores are taken // from KingDanger[]. Various little "meta-bonuses" measuring the strength // of the enemy attack are added up into an integer, which is used as an @@ -213,8 +216,8 @@ namespace { template void init_eval_info(const Position& pos, EvalInfo& ei); - template - Score evaluate_pieces(const Position& pos, EvalInfo& ei, Score* mobility); + template + Score evaluate_pieces(const Position& pos, EvalInfo& ei, Score* mobility, Bitboard* mobilityArea); template Score evaluate_king(const Position& pos, const EvalInfo& ei); @@ -316,9 +319,21 @@ Value do_evaluate(const Position& pos) { init_eval_info(pos, ei); init_eval_info(pos, ei); + // Do not include in mobility squares protected by enemy pawns or occupied by our pieces + Bitboard mobilityArea[] = { ~(ei.attackedBy[BLACK][PAWN] | pos.pieces(WHITE, PAWN, KING)), + ~(ei.attackedBy[WHITE][PAWN] | pos.pieces(BLACK, PAWN, KING)) }; + // Evaluate pieces and mobility - score += evaluate_pieces(pos, ei, mobility) - - evaluate_pieces(pos, ei, mobility); + score += evaluate_pieces(pos, ei, mobility, mobilityArea); + + // Sum up all attacked squares (updated in evaluate_pieces) + ei.attackedBy[WHITE][ALL_PIECES] = ei.attackedBy[WHITE][PAWN] | ei.attackedBy[WHITE][KNIGHT] + | ei.attackedBy[WHITE][BISHOP] | ei.attackedBy[WHITE][ROOK] + | ei.attackedBy[WHITE][QUEEN] | ei.attackedBy[WHITE][KING]; + + ei.attackedBy[BLACK][ALL_PIECES] = ei.attackedBy[BLACK][PAWN] | ei.attackedBy[BLACK][KNIGHT] + | ei.attackedBy[BLACK][BISHOP] | ei.attackedBy[BLACK][ROOK] + | ei.attackedBy[BLACK][QUEEN] | ei.attackedBy[BLACK][KING]; score += apply_weight(mobility[WHITE] - mobility[BLACK], Weights[Mobility]); @@ -381,6 +396,8 @@ Value do_evaluate(const Position& pos) { Tracing::add_term(Tracing::PST, pos.psq_score()); Tracing::add_term(Tracing::IMBALANCE, ei.mi->material_value()); Tracing::add_term(PAWN, ei.pi->pawns_value()); + Tracing::add_term(Tracing::MOBILITY, apply_weight(mobility[WHITE], Weights[Mobility]) + , apply_weight(mobility[BLACK], Weights[Mobility])); Score w = ei.mi->space_weight() * evaluate_space(pos, ei); Score b = ei.mi->space_weight() * evaluate_space(pos, ei); Tracing::add_term(Tracing::SPACE, apply_weight(w, Weights[Space]), apply_weight(b, Weights[Space])); @@ -450,7 +467,7 @@ Value do_evaluate(const Position& pos) { // evaluate_pieces() assigns bonuses and penalties to the pieces of a given color template - Score evaluate_pieces(const Position& pos, EvalInfo& ei, Score* mobility, Bitboard mobilityArea) { + Score evaluate_pieces(const Position& pos, EvalInfo& ei, Score* mobility, Bitboard* mobilityArea) { Bitboard b; Square s; @@ -482,11 +499,19 @@ Value do_evaluate(const Position& pos) { ei.kingAdjacentZoneAttacksCount[Us] += popcount(bb); } - int mob = Pt != QUEEN ? popcount(b & mobilityArea) - : popcount(b & mobilityArea); + if (Pt == QUEEN) + b &= ~( ei.attackedBy[Them][KNIGHT] + | ei.attackedBy[Them][BISHOP] + | ei.attackedBy[Them][ROOK]); + + int mob = Pt != QUEEN ? popcount(b & mobilityArea[Us]) + : popcount(b & mobilityArea[Us]); mobility[Us] += MobilityBonus[Pt][mob]; + if (mob <= 1 && (EdgeBB & s)) + score -= LowMobPenalty; + // Decrease score if we are attacked by an enemy pawn. The remaining part // of threat evaluation must be done later when we have full attack info. if (ei.attackedBy[Them][PAWN] & s) @@ -562,36 +587,16 @@ Value do_evaluate(const Position& pos) { if (Trace) Tracing::terms[Us][Pt] = score; - return score; - } - + const PieceType NextPt = (Us == WHITE ? Pt : PieceType(Pt + 1)); - // evaluate_pieces() assigns bonuses and penalties to all the - // pieces of a given color. - - template - Score evaluate_pieces(const Position& pos, EvalInfo& ei, Score* mobility) { - - const Color Them = (Us == WHITE ? BLACK : WHITE); - - // 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, PAWN, KING)); - - Score score = evaluate_pieces(pos, ei, mobility, mobilityArea) - + evaluate_pieces(pos, ei, mobility, mobilityArea) - + evaluate_pieces(pos, ei, mobility, mobilityArea) - + evaluate_pieces(pos, ei, mobility, mobilityArea); - - // Sum up all attacked squares (updated in evaluate_pieces) - ei.attackedBy[Us][ALL_PIECES] = ei.attackedBy[Us][PAWN] | ei.attackedBy[Us][KNIGHT] - | ei.attackedBy[Us][BISHOP] | ei.attackedBy[Us][ROOK] - | ei.attackedBy[Us][QUEEN] | ei.attackedBy[Us][KING]; - if (Trace) - Tracing::terms[Us][Tracing::MOBILITY] = apply_weight(mobility[Us], Weights[Mobility]); - - return score; + return score - evaluate_pieces(pos, ei, mobility, mobilityArea); } + template<> + Score evaluate_pieces(const Position&, EvalInfo&, Score*, Bitboard*) { return SCORE_ZERO; } + template<> + Score evaluate_pieces(const Position&, EvalInfo&, Score*, Bitboard*) { return SCORE_ZERO; } + // evaluate_king() assigns bonuses and penalties to a king of a given color @@ -939,7 +944,7 @@ Value do_evaluate(const Position& pos) { // Tracing function definitions - double Tracing::to_cp(Value v) { return double(v) / PawnValueMg; } + double Tracing::to_cp(Value v) { return double(v) / PawnValueEg; } void Tracing::add_term(int idx, Score wScore, Score bScore) {