]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Remove QueenOn7th and QueenOnPawn
[stockfish] / src / evaluate.cpp
index 8c84ac299777e7ff7a33f91cb2f9e439de783686..28fd8341e8d8cfad2aba6ac7c694d1eee525b002 100644 (file)
@@ -91,7 +91,7 @@ namespace {
 
   // Evaluation weights, initialized from UCI options
   enum { Mobility, PawnStructure, PassedPawns, Space, KingDangerUs, KingDangerThem };
-  Score Weights[6];
+  struct Weight { int mg, eg; } Weights[6];
 
   typedef Value V;
   #define S(mg, eg) make_score(mg, eg)
@@ -162,9 +162,7 @@ namespace {
 
   const Score Tempo            = make_score(24, 11);
   const Score RookOn7th        = make_score(11, 20);
-  const Score QueenOn7th       = make_score( 3,  8);
   const Score RookOnPawn       = make_score(10, 28);
-  const Score QueenOnPawn      = make_score( 4, 20);
   const Score RookOpenFile     = make_score(43, 21);
   const Score RookSemiopenFile = make_score(19, 10);
   const Score BishopPawns      = make_score( 8, 12);
@@ -204,8 +202,6 @@ 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];
@@ -235,8 +231,8 @@ namespace {
   Score evaluate_unstoppable_pawns(const Position& pos, Color us, const EvalInfo& ei);
 
   Value interpolate(const Score& v, Phase ph, ScaleFactor sf);
-  Score apply_weight(Score v, Score w);
-  Score weight_option(const std::string& mgOpt, const std::string& egOpt, Score internalWeight);
+  Score apply_weight(Score v, const Weight& w);
+  Weight weight_option(const std::string& mgOpt, const std::string& egOpt, Score internalWeight);
 }
 
 
@@ -516,23 +512,21 @@ Value do_evaluate(const Position& pos) {
                 score += MinorBehindPawn;
         }
 
-        if (  (Pt == ROOK || Pt == QUEEN)
-            && relative_rank(Us, s) >= RANK_5)
+        if (Pt == ROOK)
         {
-            // Major piece on 7th rank and enemy king trapped on 8th
+            // Rook on 7th rank and enemy king trapped on 8th
             if (   relative_rank(Us, s) == RANK_7
                 && relative_rank(Us, pos.king_square(Them)) == RANK_8)
-                score += Pt == ROOK ? RookOn7th : QueenOn7th;
+                score += RookOn7th;
 
-            // Major piece attacking enemy pawns on the same rank/file
-            Bitboard pawns = pos.pieces(Them, PAWN) & PseudoAttacks[ROOK][s];
-            if (pawns)
-                score += popcount<Max15>(pawns) * (Pt == ROOK ? RookOnPawn : QueenOnPawn);
-        }
+            // Rook piece attacking enemy pawns on the same rank/file
+            if (relative_rank(Us, s) >= RANK_5)
+            {
+                Bitboard pawns = pos.pieces(Them, PAWN) & PseudoAttacks[ROOK][s];
+                if (pawns)
+                    score += popcount<Max15>(pawns) * RookOnPawn;
+            }
 
-        // Special extra evaluation for rooks
-        if (Pt == ROOK)
-        {
             // Give a bonus for a rook on a open or semi-open file
             if (ei.pi->semiopen(Us, file_of(s)))
                 score += ei.pi->semiopen(Them, file_of(s)) ? RookOpenFile : RookSemiopenFile;
@@ -631,6 +625,7 @@ Value do_evaluate(const Position& pos) {
         // the pawn shelter (current 'score' value).
         attackUnits =  std::min(20, (ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them]) / 2)
                      + 3 * (ei.kingAdjacentZoneAttacksCount[Them] + popcount<Max15>(undefended))
+                     + 2 * (ei.pinnedPieces[Us] != 0)
                      - mg_value(score) / 32;
 
         // Analyse the enemy's safe queen contact checks. Firstly, find the
@@ -695,10 +690,6 @@ Value do_evaluate(const Position& pos) {
         if (b)
             attackUnits += KnightCheck * popcount<Max15>(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));
 
@@ -930,22 +921,19 @@ Value do_evaluate(const Position& pos) {
   }
 
   // apply_weight() weights score v by score w trying to prevent overflow
-  Score apply_weight(Score v, Score w) {
+  Score apply_weight(Score v, const Weight& w) {
 
-    return make_score((int(mg_value(v)) * mg_value(w)) / 0x100,
-                      (int(eg_value(v)) * eg_value(w)) / 0x100);
+    return make_score(mg_value(v) * w.mg / 256, eg_value(v) * w.eg / 256);
   }
 
   // weight_option() computes the value of an evaluation weight, by combining
   // two UCI-configurable weights (midgame and endgame) with an internal weight.
 
-  Score weight_option(const std::string& mgOpt, const std::string& egOpt, Score internalWeight) {
-
-    // Scale option value from 100 to 256
-    int mg = Options[mgOpt] * 256 / 100;
-    int eg = Options[egOpt] * 256 / 100;
+  Weight weight_option(const std::string& mgOpt, const std::string& egOpt, Score internalWeight) {
 
-    return apply_weight(make_score(mg, eg), internalWeight);
+    Weight w = { Options[mgOpt] * mg_value(internalWeight) / 100,
+                 Options[egOpt] * eg_value(internalWeight) / 100 };
+    return w;
   }
 
 
@@ -967,8 +955,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 - 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";
         break;
     default:
         ss << std::setw(20) << name << " | " << std::noshowpos
@@ -976,9 +964,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";
     }
   }
 
@@ -987,12 +974,13 @@ Value do_evaluate(const Position& pos) {
     std::memset(terms, 0, sizeof(terms));
 
     Value v = do_evaluate<true>(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);
@@ -1007,14 +995,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();
   }