X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=fd78d5af368d2aa3f1b03a1a08882a45c7f8e83b;hp=c9b2d31b0d42f1e5f61b2ee63b3e8ee65c69da8d;hb=422c9c2acd5afb793ab8e26ef9641f7c348cd549;hpb=7bdb8c9c5c82629f50252151afd542316665c505 diff --git a/src/evaluate.cpp b/src/evaluate.cpp index c9b2d31b..fd78d5af 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -204,6 +204,8 @@ namespace { const int BishopCheck = 2; const int KnightCheck = 3; + const int UnsupportedPinnedPiece = 2; + // KingDanger[Color][attackUnits] contains the actual king danger weighted // scores, indexed by color and by a calculated integer number. Score KingDanger[COLOR_NB][128]; @@ -494,16 +496,16 @@ Value do_evaluate(const Position& pos) { if (ei.attackedBy[Them][PAWN] & s) score -= ThreatenedByPawn[Pt]; - // Penalty for bishop with same coloured pawns - if (Pt == BISHOP) - score -= BishopPawns * ei.pi->pawns_on_same_color_squares(Us, s); - - // Penalty for knight when there are few enemy pawns - if (Pt == KNIGHT) - score -= KnightPawns * std::max(5 - pos.count(Them), 0); - if (Pt == BISHOP || Pt == KNIGHT) { + // Penalty for bishop with same colored pawns + if (Pt == BISHOP) + score -= BishopPawns * ei.pi->pawns_on_same_color_squares(Us, s); + + // Penalty for knight when there are few enemy pawns + if (Pt == KNIGHT) + score -= KnightPawns * std::max(5 - pos.count(Them), 0); + // Bishop and knight outposts squares if (!(pos.pieces(Them, PAWN) & pawn_attack_span(Us, s))) score += evaluate_outposts(pos, ei, s); @@ -693,6 +695,10 @@ Value do_evaluate(const Position& pos) { if (b) attackUnits += KnightCheck * popcount(b); + // Penalty for pinned pieces not defended by a pawn + if (ei.pinnedPieces[Us] & ~ei.attackedBy[Us][PAWN]) + attackUnits += UnsupportedPinnedPiece; + // To index KingDanger[] attackUnits must be in [0, 99] range attackUnits = std::min(99, std::max(0, attackUnits)); @@ -961,8 +967,8 @@ Value do_evaluate(const Position& pos) { switch (idx) { case PST: case IMBALANCE: case PAWN: case TOTAL: ss << std::setw(20) << name << " | --- --- | --- --- | " - << std::setw(6) << to_cp(mg_value(wScore)) << " " - << std::setw(6) << to_cp(eg_value(wScore)) << " \n"; + << std::setw(5) << to_cp(mg_value(wScore - bScore)) << " " + << std::setw(5) << to_cp(eg_value(wScore - bScore)) << " \n"; break; default: ss << std::setw(20) << name << " | " << std::noshowpos @@ -970,9 +976,8 @@ Value do_evaluate(const Position& pos) { << std::setw(5) << to_cp(eg_value(wScore)) << " | " << std::setw(5) << to_cp(mg_value(bScore)) << " " << std::setw(5) << to_cp(eg_value(bScore)) << " | " - << std::showpos - << std::setw(6) << to_cp(mg_value(wScore - bScore)) << " " - << std::setw(6) << to_cp(eg_value(wScore - bScore)) << " \n"; + << std::setw(5) << to_cp(mg_value(wScore - bScore)) << " " + << std::setw(5) << to_cp(eg_value(wScore - bScore)) << " \n"; } } @@ -981,12 +986,13 @@ Value do_evaluate(const Position& pos) { std::memset(terms, 0, sizeof(terms)); Value v = do_evaluate(pos); + v = pos.side_to_move() == WHITE ? v : -v; // White's point of view std::stringstream ss; - ss << std::showpoint << std::showpos << std::fixed << std::setprecision(2) - << " Eval term | White | Black | Total \n" - << " | MG EG | MG EG | MG EG \n" - << "---------------------+-------------+-------------+---------------\n"; + ss << std::showpoint << std::noshowpos << std::fixed << std::setprecision(2) + << " Eval term | White | Black | Total \n" + << " | MG EG | MG EG | MG EG \n" + << "---------------------+-------------+-------------+-------------\n"; format_row(ss, "Material, PST, Tempo", PST); format_row(ss, "Material imbalance", IMBALANCE); @@ -1001,14 +1007,10 @@ Value do_evaluate(const Position& pos) { format_row(ss, "Passed pawns", PASSED); format_row(ss, "Space", SPACE); - ss << "---------------------+-------------+-------------+---------------\n"; + ss << "---------------------+-------------+-------------+-------------\n"; format_row(ss, "Total", TOTAL); - ss << "\nScaling: " << std::noshowpos - << std::setw(6) << 100.0 * ei.mi->game_phase() / 128.0 << "% MG, " - << std::setw(6) << 100.0 * (1.0 - ei.mi->game_phase() / 128.0) << "% * " - << std::setw(6) << (100.0 * sf) / SCALE_FACTOR_NORMAL << "% EG.\n" - << "Total evaluation: " << to_cp(v); + ss << "\nTotal Evaluation: " << to_cp(v) << " (white side)\n"; return ss.str(); }