]> git.sesse.net Git - stockfish/commitdiff
Sync with master
authorMarco Costalba <mcostalba@gmail.com>
Sat, 7 Feb 2015 09:31:47 +0000 (10:31 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 7 Feb 2015 09:32:28 +0000 (10:32 +0100)
bench: 7696257

src/Makefile
src/evaluate.cpp
src/material.cpp
src/pawns.cpp

index 769b9d34830780e3a0624e3a3ea043649c534399..397b4046a1f14d1379cff2259bb74221aba10cbd 100644 (file)
@@ -448,16 +448,13 @@ gcc-profile-prepare:
 
 gcc-profile-make:
        $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
-       EXTRACXXFLAGS='-fprofile-arcs' \
+       EXTRACXXFLAGS='-fprofile-generate' \
        EXTRALDFLAGS='-lgcov' \
        all
 
 gcc-profile-use:
-# Deleting corrupt ucioption.gc* profile files is necessary to avoid an 
-# "internal compiler error" for gcc versions 4.7.x
-       @rm -f ucioption.gc*
        $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
-       EXTRACXXFLAGS='-fbranch-probabilities' \
+       EXTRACXXFLAGS='-fprofile-use -fno-peel-loops -fno-tracer' \
        EXTRALDFLAGS='-lgcov' \
        all
 
index 8e5a7f82042d7d88a22ca39f013e3b9473793e40..822be015bdf6395c6a66f34ebf926f7849f4415e 100644 (file)
@@ -91,7 +91,7 @@ namespace {
   // Evaluation weights, indexed by evaluation term
   enum { Mobility, PawnStructure, PassedPawns, Space, KingSafety };
   const struct Weight { int mg, eg; } Weights[] = {
-    {289, 344}, {233, 201}, {221, 273}, {46, 0}, {324, 0}
+    {289, 344}, {233, 201}, {221, 273}, {46, 0}, {322, 0}
   };
 
   #define V(v) Value(v)
@@ -162,6 +162,7 @@ namespace {
   const Score TrappedRook        = S(92,  0);
   const Score Unstoppable        = S( 0, 20);
   const Score Hanging            = S(31, 26);
+  const Score PawnAttackThreat   = S(20, 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,15 +187,15 @@ namespace {
   // index to KingDanger[].
   //
   // KingAttackWeights[PieceType] contains king attack weights by piece type
-  const int KingAttackWeights[] = { 0, 0, 8, 4, 4, 1 };
+  const int KingAttackWeights[] = { 0, 0, 7, 5, 4, 1 };
 
   // Bonuses for enemy's safe checks
   const int QueenContactCheck = 89;
-  const int RookContactCheck  = 72;
-  const int QueenCheck        = 51;
-  const int RookCheck         = 38;
-  const int BishopCheck       = 5;
-  const int KnightCheck       = 16;
+  const int RookContactCheck  = 71;
+  const int QueenCheck        = 50;
+  const int RookCheck         = 37;
+  const int BishopCheck       = 6;
+  const int KnightCheck       = 14;
 
   // KingDanger[attackUnits] contains the actual king danger weighted
   // scores, indexed by a calculated integer number.
@@ -412,10 +413,10 @@ namespace {
         // attacked and undefended squares around our king and the quality of
         // the pawn shelter (current 'score' value).
         attackUnits =  std::min(74, ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them])
-                     + 9 * ei.kingAdjacentZoneAttacksCount[Them]
+                     + 8 * ei.kingAdjacentZoneAttacksCount[Them]
                      + 25 * popcount<Max15>(undefended)
-                     +  10 * (ei.pinnedPieces[Us] != 0)
-                     - mg_value(score) / 8
+                     +  11 * (ei.pinnedPieces[Us] != 0)
+                     - mg_value(score) * 31 / 256
                      - !pos.count<QUEEN>(Them) * 60;
 
         // Analyse the enemy's safe queen contact checks. Firstly, find the
@@ -492,7 +493,12 @@ namespace {
   template<Color Us, bool Trace>
   Score evaluate_threats(const Position& pos, const EvalInfo& ei) {
 
-    const Color Them = (Us == WHITE ? BLACK : WHITE);
+    const Color Them        = (Us == WHITE ? BLACK    : WHITE);
+    const Square Up         = (Us == WHITE ? DELTA_N  : DELTA_S);
+    const Square Left       = (Us == WHITE ? DELTA_NW : DELTA_SE);
+    const Square Right      = (Us == WHITE ? DELTA_NE : DELTA_SW);
+    const Bitboard TRank2BB = (Us == WHITE ? Rank2BB  : Rank7BB);
+    const Bitboard TRank7BB = (Us == WHITE ? Rank7BB  : Rank2BB);
 
     enum { Defended, Weak };
     enum { Minor, Major };
@@ -541,6 +547,21 @@ namespace {
             score += more_than_one(b) ? KingOnMany : KingOnOne;
     }
 
+    // Add bonus for safe pawn pushes which attacks an enemy piece
+    b = pos.pieces(Us, PAWN) & ~TRank7BB;
+    b = shift_bb<Up>(b | (shift_bb<Up>(b & TRank2BB) & ~pos.pieces()));
+
+    b &=  ~pos.pieces()
+        & ~ei.attackedBy[Them][PAWN]
+        & (ei.attackedBy[Us][PAWN] | ~ei.attackedBy[Them][ALL_PIECES]);
+
+    b =  (shift_bb<Left>(b) | shift_bb<Right>(b))
+       &  pos.pieces(Them)
+       & ~ei.attackedBy[Us][PAWN];
+
+    if(b)
+        score += popcount<Max15>(b) * PawnAttackThreat;
+
     if (Trace)
         Tracing::write(Tracing::THREAT, Us, score);
 
@@ -891,7 +912,7 @@ namespace Eval {
 
   void init() {
 
-    const double MaxSlope = 8.5;
+    const double MaxSlope = 8.7;
     const double Peak = 1280;
     double t = 0.0;
 
index e22942128f4a98974f856ecefb836c15b091ff8a..ebf5adff854abc4bb6770c6547795e72c7d791c7 100644 (file)
@@ -64,31 +64,28 @@ namespace {
   Endgame<KPsK>   ScaleKPsK[]   = { Endgame<KPsK>(WHITE),   Endgame<KPsK>(BLACK) };
   Endgame<KPKP>   ScaleKPKP[]   = { Endgame<KPKP>(WHITE),   Endgame<KPKP>(BLACK) };
 
-  // Helper templates used to detect a given material distribution
-  template<Color Us> bool is_KXK(const Position& pos) {
-    const Color Them = (Us == WHITE ? BLACK : WHITE);
-    return  !more_than_one(pos.pieces(Them))
-          && pos.non_pawn_material(Us) >= RookValueMg;
+  // Helper used to detect a given material distribution
+  bool is_KXK(const Position& pos, Color us) {
+    return  !more_than_one(pos.pieces(~us))
+          && pos.non_pawn_material(us) >= RookValueMg;
   }
 
-  template<Color Us> bool is_KBPsKs(const Position& pos) {
-    return   pos.non_pawn_material(Us) == BishopValueMg
-          && pos.count<BISHOP>(Us) == 1
-          && pos.count<PAWN  >(Us) >= 1;
+  bool is_KBPsKs(const Position& pos, Color us) {
+    return   pos.non_pawn_material(us) == BishopValueMg
+          && pos.count<BISHOP>(us) == 1
+          && pos.count<PAWN  >(us) >= 1;
   }
 
-  template<Color Us> bool is_KQKRPs(const Position& pos) {
-    const Color Them = (Us == WHITE ? BLACK : WHITE);
-    return  !pos.count<PAWN>(Us)
-          && pos.non_pawn_material(Us) == QueenValueMg
-          && pos.count<QUEEN>(Us)  == 1
-          && pos.count<ROOK>(Them) == 1
-          && pos.count<PAWN>(Them) >= 1;
+  bool is_KQKRPs(const Position& pos, Color us) {
+    return  !pos.count<PAWN>(us)
+          && pos.non_pawn_material(us) == QueenValueMg
+          && pos.count<QUEEN>(us)  == 1
+          && pos.count<ROOK>(~us) == 1
+          && pos.count<PAWN>(~us) >= 1;
   }
 
   /// imbalance() calculates the imbalance by comparing the piece count of each
   /// piece type for both colors.
-
   template<Color Us>
   int imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
 
@@ -142,17 +139,12 @@ Entry* probe(const Position& pos) {
   if ((e->evaluationFunction = pos.this_thread()->endgames.probe<Value>(key)) != nullptr)
       return e;
 
-  if (is_KXK<WHITE>(pos))
-  {
-      e->evaluationFunction = &EvaluateKXK[WHITE];
-      return e;
-  }
-
-  if (is_KXK<BLACK>(pos))
-  {
-      e->evaluationFunction = &EvaluateKXK[BLACK];
-      return e;
-  }
+  for (Color c = WHITE; c <= BLACK; ++c)
+      if (is_KXK(pos, c))
+      {
+          e->evaluationFunction = &EvaluateKXK[c];
+          return e;
+      }
 
   // OK, we didn't find any special evaluation function for the current material
   // configuration. Is there a suitable specialized scaling function?
@@ -167,17 +159,14 @@ Entry* probe(const Position& pos) {
   // We didn't find any specialized scaling function, so fall back on generic
   // ones that refer to more than one material distribution. Note that in this
   // case we don't return after setting the function.
-  if (is_KBPsKs<WHITE>(pos))
-      e->scalingFunction[WHITE] = &ScaleKBPsK[WHITE];
-
-  if (is_KBPsKs<BLACK>(pos))
-      e->scalingFunction[BLACK] = &ScaleKBPsK[BLACK];
-
-  if (is_KQKRPs<WHITE>(pos))
-      e->scalingFunction[WHITE] = &ScaleKQKRPs[WHITE];
+  for (Color c = WHITE; c <= BLACK; ++c)
+  {
+    if (is_KBPsKs(pos, c))
+        e->scalingFunction[c] = &ScaleKBPsK[c];
 
-  else if (is_KQKRPs<BLACK>(pos))
-      e->scalingFunction[BLACK] = &ScaleKQKRPs[BLACK];
+    else if (is_KQKRPs(pos, c))
+        e->scalingFunction[c] = &ScaleKQKRPs[c];
+  }
 
   Value npm_w = pos.non_pawn_material(WHITE);
   Value npm_b = pos.non_pawn_material(BLACK);
index 798bc0a070319dc846986535e4480d9e3442d349..ef456307cafbacb4479a53627a7a1d7b58aa362d 100644 (file)
@@ -63,33 +63,33 @@ namespace {
 
   // Weakness of our pawn shelter in front of the king by [distance from edge][rank]
   const Value ShelterWeakness[][RANK_NB] = {
-  { V( 99), V(23), V(24), V(54), V(85), V( 93), V(107) },
-  { V(119), V( 2), V(28), V(72), V(96), V(104), V(114) },
-  { V(103), V( 6), V(47), V(74), V(84), V(103), V( 94) },
-  { V( 78), V(10), V(41), V(64), V(88), V( 92), V(115) } };
+  { V( 99), V(20), V(26), V(54), V(85), V( 92), V(108) },
+  { V(117), V( 1), V(27), V(71), V(94), V(104), V(118) },
+  { V(104), V( 4), V(51), V(76), V(82), V(102), V( 97) },
+  { V( 80), V(12), V(43), V(65), V(88), V( 91), V(115) } };
 
   // Danger of enemy pawns moving toward our king by [type][distance from edge][rank]
   const Value StormDanger[][4][RANK_NB] = {
-  { { V( 0),  V(  65), V( 125), V(37), V(30) },
-    { V( 0),  V(  57), V( 136), V(39), V(24) },
-    { V( 0),  V(  50), V( 114), V(45), V(29) },
-    { V( 0),  V(  58), V( 129), V(56), V(34) } },
-  { { V(20),  V(  45), V(  91), V(47), V(20) },
-    { V(25),  V(  23), V( 105), V(38), V(14) },
-    { V(21),  V(  37), V(  99), V(35), V(21) },
-    { V(30),  V(  18), V( 105), V(38), V(28) } },
-  { { V( 0),  V(   0), V(  81), V(13), V( 4) },
-    { V( 0),  V(   0), V( 169), V(30), V( 4) },
-    { V( 0),  V(   0), V( 166), V(24), V( 6) },
-    { V( 0),  V(   0), V( 164), V(24), V(11) } },
-  { { V( 0),  V(-289), V(-297), V(57), V(29) },
-    { V( 0),  V(  66), V( 136), V(43), V(16) },
-    { V( 0),  V(  66), V( 141), V(50), V(31) },
-    { V( 0),  V(  63), V( 126), V(52), V(23) } } };
+  { { V( 0),  V(  65), V( 126), V(36), V(30) },
+    { V( 0),  V(  55), V( 135), V(36), V(23) },
+    { V( 0),  V(  47), V( 116), V(45), V(26) },
+    { V( 0),  V(  62), V( 127), V(57), V(34) } },
+  { { V(21),  V(  45), V(  93), V(50), V(19) },
+    { V(23),  V(  24), V( 105), V(41), V(13) },
+    { V(23),  V(  36), V( 101), V(38), V(20) },
+    { V(30),  V(  19), V( 110), V(41), V(27) } },
+  { { V( 0),  V(   0), V(  81), V(14), V( 4) },
+    { V( 0),  V(   0), V( 169), V(30), V( 3) },
+    { V( 0),  V(   0), V( 168), V(24), V( 5) },
+    { V( 0),  V(   0), V( 162), V(26), V(10) } },
+  { { V( 0),  V(-283), V(-298), V(57), V(29) },
+    { V( 0),  V(  63), V( 137), V(42), V(18) },
+    { V( 0),  V(  67), V( 145), V(49), V(33) },
+    { V( 0),  V(  62), V( 126), V(53), V(21) } } };
 
   // Max bonus for king safety. Corresponds to start position with all the pawns
   // in front of the king and no enemy pawn on the horizon.
-  const Value MaxSafetyBonus = V(252);
+  const Value MaxSafetyBonus = V(258);
 
   #undef S
   #undef V
@@ -147,7 +147,7 @@ namespace {
         // If the pawn is passed, isolated, connected or a lever it cannot be
         // backward. If there are friendly pawns behind on adjacent files
         // it cannot be backward either.
-        if (   (passed | isolated | connected | lever)
+        if (   (passed | isolated | lever | connected)
             || (ourPawns & pawn_attack_span(Them, s)))
             backward = false;
         else