]> git.sesse.net Git - stockfish/commitdiff
Retire Material::space_weight()
authorMarco Costalba <mcostalba@gmail.com>
Wed, 31 Dec 2014 09:41:20 +0000 (10:41 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 2 Jan 2015 09:02:28 +0000 (10:02 +0100)
Move all in evaluation.

Simplify the code and concentrate in a single place
all the logic behind space evaluation, making it much
more clear.

Verified also at STC it does not regress due to a possible
slow down:

LLR: 3.91 (-2.94,2.94) [-3.00,1.00]
Total: 65744 W: 13285 L: 13194 D: 39265

No functional change.

src/evaluate.cpp
src/material.cpp
src/material.h

index 85ac0dab77c2373c7c292f7c478c1681b2a23518..e4c2bbcb6365a9b5e5744960a4eaa689ade2312d 100644 (file)
@@ -635,10 +635,10 @@ namespace {
   // space evaluation is a simple bonus based on the number of safe squares
   // available for minor pieces on the central four files on ranks 2--4. Safe
   // squares one, two or three squares behind a friendly pawn are counted
-  // twice. Finally, the space bonus is scaled by a weight taken from the
-  // material hash table. The aim is to improve play on game opening.
+  // twice. Finally, the space bonus is multiplied by a weight. The aim is to
+  // improve play on game opening.
   template<Color Us>
-  Score evaluate_space(const Position& pos, const EvalInfo& ei, Score weight) {
+  Score evaluate_space(const Position& pos, const EvalInfo& ei) {
 
     const Color Them = (Us == WHITE ? BLACK : WHITE);
 
@@ -659,7 +659,11 @@ namespace {
     assert(unsigned(safe >> (Us == WHITE ? 32 : 0)) == 0);
 
     // Count safe + (behind & safe) with a single popcount
-    return popcount<Full>((Us == WHITE ? safe << 32 : safe >> 32) | (behind & safe)) * weight;
+    int bonus = popcount<Full>((Us == WHITE ? safe << 32 : safe >> 32) | (behind & safe));
+    int weight =  pos.count<KNIGHT>(Us) + pos.count<BISHOP>(Us)
+                + pos.count<KNIGHT>(Them) + pos.count<BISHOP>(Them);
+
+    return make_score(bonus * weight * weight, 0);
   }
 
 
@@ -731,12 +735,10 @@ namespace {
             score -= int(relative_rank(BLACK, frontmost_sq(BLACK, b))) * Unstoppable;
     }
 
-    // Evaluate space for both sides, only in middlegame
-    if (ei.mi->space_weight())
+    // Evaluate space for both sides, only during opening
+    if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) >= 2 * QueenValueMg + 4 * RookValueMg + 2 * KnightValueMg)
     {
-        Score s =  evaluate_space<WHITE>(pos, ei, ei.mi->space_weight())
-                 - evaluate_space<BLACK>(pos, ei, ei.mi->space_weight());
-
+        Score s = evaluate_space<WHITE>(pos, ei) - evaluate_space<BLACK>(pos, ei);
         score += apply_weight(s, Weights[Space]);
     }
 
@@ -784,9 +786,8 @@ namespace {
         Tracing::write(PAWN, ei.pi->pawns_score());
         Tracing::write(Tracing::MOBILITY, apply_weight(mobility[WHITE], Weights[Mobility])
                                         , apply_weight(mobility[BLACK], Weights[Mobility]));
-        Score w = evaluate_space<WHITE>(pos, ei, ei.mi->space_weight());
-        Score b = evaluate_space<BLACK>(pos, ei, ei.mi->space_weight());
-        Tracing::write(Tracing::SPACE, apply_weight(w, Weights[Space]), apply_weight(b, Weights[Space]));
+        Tracing::write(Tracing::SPACE, apply_weight(evaluate_space<WHITE>(pos, ei), Weights[Space])
+                                     , apply_weight(evaluate_space<BLACK>(pos, ei), Weights[Space]));
         Tracing::write(Tracing::TOTAL, score);
         Tracing::ei = ei;
         Tracing::sf = sf;
index 7047afb1522511e6affde31d09e56282372f0f87..6aeb117aea5cf54befa8f714d3ae4e1eb6eeff5d 100644 (file)
@@ -223,15 +223,6 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
   if (pos.count<PAWN>(BLACK) == 1 && npm_b - npm_w <= BishopValueMg)
       e->factor[BLACK] = (uint8_t) SCALE_FACTOR_ONEPAWN;
 
-  // Compute the space weight
-  if (npm_w + npm_b >= 2 * QueenValueMg + 4 * RookValueMg + 2 * KnightValueMg)
-  {
-      int minorPieceCount =  pos.count<KNIGHT>(WHITE) + pos.count<BISHOP>(WHITE)
-                           + pos.count<KNIGHT>(BLACK) + pos.count<BISHOP>(BLACK);
-
-      e->spaceWeight = make_score(minorPieceCount * minorPieceCount, 0);
-  }
-
   // Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder
   // for the bishop pair "extended piece", which allows us to be more flexible
   // in defining bishop pair bonuses.
index 754d05230093ed22db2be7045e46fe0f6811e9fc..581e7585722691a3c808775a52c970fa4217d63d 100644 (file)
@@ -39,7 +39,6 @@ namespace Material {
 struct Entry {
 
   Score imbalance() const { return make_score(value, value); }
-  Score space_weight() const { return spaceWeight; }
   Phase game_phase() const { return gamePhase; }
   bool specialized_eval_exists() const { return evaluationFunction != NULL; }
   Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); }
@@ -61,7 +60,6 @@ struct Entry {
   uint8_t factor[COLOR_NB];
   EndgameBase<Value>* evaluationFunction;
   EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB];
-  Score spaceWeight;
   Phase gamePhase;
 };