]> git.sesse.net Git - stockfish/commitdiff
Reformat piece values arrays
authorMarco Costalba <mcostalba@gmail.com>
Mon, 20 Aug 2012 17:41:28 +0000 (18:41 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 20 Aug 2012 18:17:58 +0000 (19:17 +0100)
And rename stuff while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/endgame.cpp
src/evaluate.cpp
src/material.cpp
src/movepick.cpp
src/notation.cpp
src/position.cpp
src/search.cpp
src/types.h

index ef55119b76f811f4fb75e038000af6f7491336f5..dbf10582ac8964fdf3f047d6d93c54b202274c5d 100644 (file)
@@ -141,7 +141,7 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
   Square loserKSq = pos.king_square(weakerSide);
 
   Value result =   pos.non_pawn_material(strongerSide)
-                 + pos.piece_count(strongerSide, PAWN) * PawnValueEndgame
+                 + pos.piece_count(strongerSide, PAWN) * PawnValueEg
                  + MateTable[loserKSq]
                  + DistanceBonus[square_distance(winnerKSq, loserKSq)];
 
@@ -162,7 +162,7 @@ Value Endgame<KBNK>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
   assert(pos.piece_count(weakerSide, PAWN) == VALUE_ZERO);
-  assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame + BishopValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == KnightValueMg + BishopValueMg);
   assert(pos.piece_count(strongerSide, BISHOP) == 1);
   assert(pos.piece_count(strongerSide, KNIGHT) == 1);
   assert(pos.piece_count(strongerSide, PAWN) == 0);
@@ -225,9 +225,7 @@ Value Endgame<KPK>::operator()(const Position& pos) const {
   if (!Bitbases::probe_kpk(wksq, wpsq, bksq, stm))
       return VALUE_DRAW;
 
-  Value result =  VALUE_KNOWN_WIN
-                + PawnValueEndgame
-                + Value(rank_of(wpsq));
+  Value result = VALUE_KNOWN_WIN + PawnValueEg + Value(rank_of(wpsq));
 
   return strongerSide == pos.side_to_move() ? result : -result;
 }
@@ -240,7 +238,7 @@ Value Endgame<KPK>::operator()(const Position& pos) const {
 template<>
 Value Endgame<KRKP>::operator()(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == RookValueMg);
   assert(pos.piece_count(strongerSide, PAWN) == 0);
   assert(pos.non_pawn_material(weakerSide) == 0);
   assert(pos.piece_count(weakerSide, PAWN) == 1);
@@ -266,13 +264,13 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
 
   // If the stronger side's king is in front of the pawn, it's a win
   if (wksq < bpsq && file_of(wksq) == file_of(bpsq))
-      result = RookValueEndgame - Value(square_distance(wksq, bpsq));
+      result = RookValueEg - Value(square_distance(wksq, bpsq));
 
   // If the weaker side's king is too far from the pawn and the rook,
   // it's a win
   else if (   square_distance(bksq, bpsq) - (tempo ^ 1) >= 3
            && square_distance(bksq, wrsq) >= 3)
-      result = RookValueEndgame - Value(square_distance(wksq, bpsq));
+      result = RookValueEg - Value(square_distance(wksq, bpsq));
 
   // If the pawn is far advanced and supported by the defending king,
   // the position is drawish
@@ -297,9 +295,9 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
 template<>
 Value Endgame<KRKB>::operator()(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == RookValueMg);
   assert(pos.piece_count(strongerSide, PAWN) == 0);
-  assert(pos.non_pawn_material(weakerSide) == BishopValueMidgame);
+  assert(pos.non_pawn_material(weakerSide) == BishopValueMg);
   assert(pos.piece_count(weakerSide, PAWN) == 0);
   assert(pos.piece_count(weakerSide, BISHOP) == 1);
 
@@ -313,9 +311,9 @@ Value Endgame<KRKB>::operator()(const Position& pos) const {
 template<>
 Value Endgame<KRKN>::operator()(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == RookValueMg);
   assert(pos.piece_count(strongerSide, PAWN) == 0);
-  assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame);
+  assert(pos.non_pawn_material(weakerSide) == KnightValueMg);
   assert(pos.piece_count(weakerSide, PAWN) == 0);
   assert(pos.piece_count(weakerSide, KNIGHT) == 1);
 
@@ -336,16 +334,16 @@ Value Endgame<KRKN>::operator()(const Position& pos) const {
 template<>
 Value Endgame<KQKR>::operator()(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == QueenValueMg);
   assert(pos.piece_count(strongerSide, PAWN) == 0);
-  assert(pos.non_pawn_material(weakerSide) == RookValueMidgame);
+  assert(pos.non_pawn_material(weakerSide) == RookValueMg);
   assert(pos.piece_count(weakerSide, PAWN) == 0);
 
   Square winnerKSq = pos.king_square(strongerSide);
   Square loserKSq = pos.king_square(weakerSide);
 
-  Value result =  QueenValueEndgame
-                - RookValueEndgame
+  Value result =  QueenValueEg
+                - RookValueEg
                 + MateTable[loserKSq]
                 + DistanceBonus[square_distance(winnerKSq, loserKSq)];
 
@@ -356,12 +354,12 @@ template<>
 Value Endgame<KBBKN>::operator()(const Position& pos) const {
 
   assert(pos.piece_count(strongerSide, BISHOP) == 2);
-  assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMg);
   assert(pos.piece_count(weakerSide, KNIGHT) == 1);
-  assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame);
+  assert(pos.non_pawn_material(weakerSide) == KnightValueMg);
   assert(!pos.pieces(PAWN));
 
-  Value result = BishopValueEndgame;
+  Value result = BishopValueEg;
   Square wksq = pos.king_square(strongerSide);
   Square bksq = pos.king_square(weakerSide);
   Square nsq = pos.piece_list(weakerSide, KNIGHT)[0];
@@ -398,7 +396,7 @@ Value Endgame<KNNK>::operator()(const Position&) const {
 template<>
 ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == BishopValueMg);
   assert(pos.piece_count(strongerSide, BISHOP) == 1);
   assert(pos.piece_count(strongerSide, PAWN) >= 1);
 
@@ -450,7 +448,7 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
 template<>
 ScaleFactor Endgame<KQKRPs>::operator()(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == QueenValueMg);
   assert(pos.piece_count(strongerSide, QUEEN) == 1);
   assert(pos.piece_count(strongerSide, PAWN) == 0);
   assert(pos.piece_count(weakerSide, ROOK) == 1);
@@ -480,9 +478,9 @@ ScaleFactor Endgame<KQKRPs>::operator()(const Position& pos) const {
 template<>
 ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == RookValueMg);
   assert(pos.piece_count(strongerSide, PAWN) == 1);
-  assert(pos.non_pawn_material(weakerSide) == RookValueMidgame);
+  assert(pos.non_pawn_material(weakerSide) == RookValueMg);
   assert(pos.piece_count(weakerSide, PAWN) == 0);
 
   Square wksq = pos.king_square(strongerSide);
@@ -598,9 +596,9 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
 template<>
 ScaleFactor Endgame<KRPPKRP>::operator()(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == RookValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == RookValueMg);
   assert(pos.piece_count(strongerSide, PAWN) == 2);
-  assert(pos.non_pawn_material(weakerSide) == RookValueMidgame);
+  assert(pos.non_pawn_material(weakerSide) == RookValueMg);
   assert(pos.piece_count(weakerSide, PAWN) == 1);
 
   Square wpsq1 = pos.piece_list(strongerSide, PAWN)[0];
@@ -673,10 +671,10 @@ ScaleFactor Endgame<KPsK>::operator()(const Position& pos) const {
 template<>
 ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == BishopValueMg);
   assert(pos.piece_count(strongerSide, BISHOP) == 1);
   assert(pos.piece_count(strongerSide, PAWN) == 1);
-  assert(pos.non_pawn_material(weakerSide) == BishopValueMidgame);
+  assert(pos.non_pawn_material(weakerSide) == BishopValueMg);
   assert(pos.piece_count(weakerSide, BISHOP) == 1);
   assert(pos.piece_count(weakerSide, PAWN) == 0);
 
@@ -728,10 +726,10 @@ ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const {
 template<>
 ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == BishopValueMg);
   assert(pos.piece_count(strongerSide, BISHOP) == 1);
   assert(pos.piece_count(strongerSide, PAWN) == 2);
-  assert(pos.non_pawn_material(weakerSide) == BishopValueMidgame);
+  assert(pos.non_pawn_material(weakerSide) == BishopValueMg);
   assert(pos.piece_count(weakerSide, BISHOP) == 1);
   assert(pos.piece_count(weakerSide, PAWN) == 0);
 
@@ -803,10 +801,10 @@ ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const {
 template<>
 ScaleFactor Endgame<KBPKN>::operator()(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == BishopValueMg);
   assert(pos.piece_count(strongerSide, BISHOP) == 1);
   assert(pos.piece_count(strongerSide, PAWN) == 1);
-  assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame);
+  assert(pos.non_pawn_material(weakerSide) == KnightValueMg);
   assert(pos.piece_count(weakerSide, KNIGHT) == 1);
   assert(pos.piece_count(weakerSide, PAWN) == 0);
 
@@ -830,7 +828,7 @@ ScaleFactor Endgame<KBPKN>::operator()(const Position& pos) const {
 template<>
 ScaleFactor Endgame<KNPK>::operator()(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame);
+  assert(pos.non_pawn_material(strongerSide) == KnightValueMg);
   assert(pos.piece_count(strongerSide, KNIGHT) == 1);
   assert(pos.piece_count(strongerSide, PAWN) == 1);
   assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
index 3b70a950a66db5ee16f9f28e050b80b5864450b0..46d9151ff1401add0287b416770108a729abf606 100644 (file)
@@ -435,8 +435,8 @@ Value do_evaluate(const Position& pos, Value& margin) {
       && sf == SCALE_FACTOR_NORMAL)
   {
       // Only the two bishops ?
-      if (   pos.non_pawn_material(WHITE) == BishopValueMidgame
-          && pos.non_pawn_material(BLACK) == BishopValueMidgame)
+      if (   pos.non_pawn_material(WHITE) == BishopValueMg
+          && pos.non_pawn_material(BLACK) == BishopValueMg)
       {
           // Check for KBP vs KB with only a single pawn that is almost
           // certainly a draw or at least two pawns.
@@ -492,7 +492,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
 
     // Init king safety tables only if we are going to use them
     if (   pos.piece_count(Us, QUEEN)
-        && pos.non_pawn_material(Us) >= QueenValueMidgame + RookValueMidgame)
+        && pos.non_pawn_material(Us) >= QueenValueMg + RookValueMg)
     {
         ei.kingRing[Them] = (b | (Us == WHITE ? b >> 8 : b << 8));
         b &= ei.attackedBy[Us][PAWN];
@@ -938,7 +938,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
         // value if the other side has a rook or queen.
         if (file_of(s) == FILE_A || file_of(s) == FILE_H)
         {
-            if (pos.non_pawn_material(Them) <= KnightValueMidgame)
+            if (pos.non_pawn_material(Them) <= KnightValueMg)
                 ebonus += ebonus / 4;
             else if (pos.pieces(Them, ROOK, QUEEN))
                 ebonus -= ebonus / 4;
@@ -1172,7 +1172,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
   // A couple of little helpers used by tracing code, to_cp() converts a value to
   // a double in centipawns scale, trace_add() stores white and black scores.
 
-  double to_cp(Value v) { return double(v) / double(PawnValueMidgame); }
+  double to_cp(Value v) { return double(v) / double(PawnValueMg); }
 
   void trace_add(int idx, Score wScore, Score bScore) {
 
index b106892bcfa83fdbae9ec553c03871a194224c32..323611779963de5f62baf564e8ae98e920a9160b 100644 (file)
@@ -63,11 +63,11 @@ namespace {
     const Color Them = (Us == WHITE ? BLACK : WHITE);
     return   pos.non_pawn_material(Them) == VALUE_ZERO
           && pos.piece_count(Them, PAWN) == 0
-          && pos.non_pawn_material(Us)   >= RookValueMidgame;
+          && pos.non_pawn_material(Us)   >= RookValueMg;
   }
 
   template<Color Us> bool is_KBPsKs(const Position& pos) {
-    return   pos.non_pawn_material(Us)   == BishopValueMidgame
+    return   pos.non_pawn_material(Us)   == BishopValueMg
           && pos.piece_count(Us, BISHOP) == 1
           && pos.piece_count(Us, PAWN)   >= 1;
   }
@@ -75,7 +75,7 @@ namespace {
   template<Color Us> bool is_KQKRPs(const Position& pos) {
     const Color Them = (Us == WHITE ? BLACK : WHITE);
     return   pos.piece_count(Us, PAWN)    == 0
-          && pos.non_pawn_material(Us)    == QueenValueMidgame
+          && pos.non_pawn_material(Us)    == QueenValueMg
           && pos.piece_count(Us, QUEEN)   == 1
           && pos.piece_count(Them, ROOK)  == 1
           && pos.piece_count(Them, PAWN)  >= 1;
@@ -191,20 +191,20 @@ MaterialEntry* MaterialTable::probe(const Position& pos) {
   }
 
   // No pawns makes it difficult to win, even with a material advantage
-  if (pos.piece_count(WHITE, PAWN) == 0 && npm_w - npm_b <= BishopValueMidgame)
+  if (pos.piece_count(WHITE, PAWN) == 0 && npm_w - npm_b <= BishopValueMg)
   {
       e->factor[WHITE] = (uint8_t)
-      (npm_w == npm_b || npm_w < RookValueMidgame ? 0 : NoPawnsSF[std::min(pos.piece_count(WHITE, BISHOP), 2)]);
+      (npm_w == npm_b || npm_w < RookValueMg ? 0 : NoPawnsSF[std::min(pos.piece_count(WHITE, BISHOP), 2)]);
   }
 
-  if (pos.piece_count(BLACK, PAWN) == 0 && npm_b - npm_w <= BishopValueMidgame)
+  if (pos.piece_count(BLACK, PAWN) == 0 && npm_b - npm_w <= BishopValueMg)
   {
       e->factor[BLACK] = (uint8_t)
-      (npm_w == npm_b || npm_b < RookValueMidgame ? 0 : NoPawnsSF[std::min(pos.piece_count(BLACK, BISHOP), 2)]);
+      (npm_w == npm_b || npm_b < RookValueMg ? 0 : NoPawnsSF[std::min(pos.piece_count(BLACK, BISHOP), 2)]);
   }
 
   // Compute the space weight
-  if (npm_w + npm_b >= 2 * QueenValueMidgame + 4 * RookValueMidgame + 2 * KnightValueMidgame)
+  if (npm_w + npm_b >= 2 * QueenValueMg + 4 * RookValueMg + 2 * KnightValueMg)
   {
       int minorPieceCount =  pos.piece_count(WHITE, KNIGHT) + pos.piece_count(WHITE, BISHOP)
                            + pos.piece_count(BLACK, KNIGHT) + pos.piece_count(BLACK, BISHOP);
index e3d29f814f041f1d01943afb50fd97faa7cd61ae..b09647953a7fe50a6647d0c21668dcea340d20d6 100644 (file)
@@ -79,8 +79,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
       killers[1].move = ss->killers[1];
 
       // Consider sligtly negative captures as good if at low depth and far from beta
-      if (ss && ss->eval < beta - PawnValueMidgame && d < 3 * ONE_PLY)
-          captureThreshold = -PawnValueMidgame;
+      if (ss && ss->eval < beta - PawnValueMg && d < 3 * ONE_PLY)
+          captureThreshold = -PawnValueMg;
 
       // Consider negative captures as good if still enough to reach beta
       else if (ss && ss->eval > beta)
@@ -131,7 +131,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, const History& h, PieceType
   phase = PROBCUT;
 
   // In ProbCut we generate only captures better than parent's captured piece
-  captureThreshold = PieceValueMidgame[pt];
+  captureThreshold = PieceValue[Mg][pt];
   ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE);
 
   if (ttMove && (!pos.is_capture(ttMove) ||  pos.see(ttMove) <= captureThreshold))
@@ -165,11 +165,11 @@ void MovePicker::score_captures() {
   for (MoveStack* cur = moves; cur != lastMove; cur++)
   {
       m = cur->move;
-      cur->score =  PieceValueMidgame[pos.piece_on(to_sq(m))]
+      cur->score =  PieceValue[Mg][pos.piece_on(to_sq(m))]
                   - type_of(pos.piece_moved(m));
 
       if (type_of(m) == PROMOTION)
-          cur->score += PieceValueMidgame[promotion_type(m)];
+          cur->score += PieceValue[Mg][promotion_type(m)];
   }
 }
 
@@ -200,7 +200,7 @@ void MovePicker::score_evasions() {
       if ((seeScore = pos.see_sign(m)) < 0)
           cur->score = seeScore - History::MaxValue; // Be sure we are at the bottom
       else if (pos.is_capture(m))
-          cur->score =  PieceValueMidgame[pos.piece_on(to_sq(m))]
+          cur->score =  PieceValue[Mg][pos.piece_on(to_sq(m))]
                       - type_of(pos.piece_moved(m)) + History::MaxValue;
       else
           cur->score = H.value(pos.piece_moved(m), to_sq(m));
index bbcb3d8eeb1545a3bc56860a7feb639e860ca51c..c4d1c439be38f0f635fa70a4f4a130352e32246a 100644 (file)
@@ -43,7 +43,7 @@ string score_to_uci(Value v, Value alpha, Value beta) {
   stringstream s;
 
   if (abs(v) < VALUE_MATE_IN_MAX_PLY)
-      s << "cp " << v * 100 / int(PawnValueMidgame);
+      s << "cp " << v * 100 / int(PawnValueMg);
   else
       s << "mate " << (v > 0 ? VALUE_MATE - v + 1 : -VALUE_MATE - v) / 2;
 
@@ -216,7 +216,7 @@ static string score_to_string(Value v) {
       s << "-#" << (VALUE_MATE + v) / 2;
 
   else
-      s << setprecision(2) << fixed << showpos << float(v) / PawnValueMidgame;
+      s << setprecision(2) << fixed << showpos << float(v) / PawnValueMg;
 
   return s.str();
 }
index 60bdeafb4ca7d6b4e2d5db620b61cdf76f852ab9..21022ae1b2c18dc7655eef0460d80cd3bdc054db 100644 (file)
@@ -36,35 +36,18 @@ using std::string;
 using std::cout;
 using std::endl;
 
-// To convert a Piece to and from a FEN char
 static const string PieceToChar(" PNBRQK  pnbrqk");
 
-// Material values arrays, indexed by Piece
-const Value PieceValueMidgame[17] = {
-  VALUE_ZERO,
-  PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
-  RookValueMidgame, QueenValueMidgame,
-  VALUE_ZERO, VALUE_ZERO, VALUE_ZERO,
-  PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
-  RookValueMidgame, QueenValueMidgame
-};
-
-const Value PieceValueEndgame[17] = {
-  VALUE_ZERO,
-  PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
-  RookValueEndgame, QueenValueEndgame,
-  VALUE_ZERO, VALUE_ZERO, VALUE_ZERO,
-  PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
-  RookValueEndgame, QueenValueEndgame
-};
-
 CACHE_LINE_ALIGNMENT
 
-Score pieceSquareTable[16][64];
+Score pieceSquareTable[16][64]; // [piece][square]
+Value PieceValue[2][18] = {     // [Mg / Eg][piece / pieceType]
+{ VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg },
+{ VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg } };
 
 namespace Zobrist {
 
-Key psq[2][8][64]; // [color][pieceType][square]/[piece count]
+Key psq[2][8][64]; // [color][pieceType][square / piece count]
 Key enpassant[8];  // [file]
 Key castle[16];    // [castleRight]
 Key side;
@@ -103,7 +86,10 @@ void init() {
 
   for (PieceType pt = PAWN; pt <= KING; pt++)
   {
-      Score v = make_score(PieceValueMidgame[pt], PieceValueEndgame[pt]);
+      PieceValue[Mg][make_piece(BLACK, pt)] = PieceValue[Mg][pt];
+      PieceValue[Eg][make_piece(BLACK, pt)] = PieceValue[Eg][pt];
+
+      Score v = make_score(PieceValue[Mg][pt], PieceValue[Eg][pt]);
 
       for (Square s = SQ_A1; s <= SQ_H8; s++)
       {
@@ -808,7 +794,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
           st->pawnKey ^= Zobrist::psq[them][PAWN][capsq];
       }
       else
-          st->npMaterial[them] -= PieceValueMidgame[capture];
+          st->npMaterial[them] -= PieceValue[Mg][capture];
 
       // Remove the captured piece
       byTypeBB[ALL_PIECES] ^= capsq;
@@ -916,7 +902,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
                          - pieceSquareTable[make_piece(us, PAWN)][to];
 
           // Update material
-          st->npMaterial[us] += PieceValueMidgame[promotion];
+          st->npMaterial[us] += PieceValue[Mg][promotion];
       }
 
       // Update pawn hash key
@@ -1221,7 +1207,7 @@ int Position::see_sign(Move m) const {
   // Early return if SEE cannot be negative because captured piece value
   // is not less then capturing one. Note that king moves always return
   // here because king midgame value is set to 0.
-  if (PieceValueMidgame[piece_on(to_sq(m))] >= PieceValueMidgame[piece_moved(m)])
+  if (PieceValue[Mg][piece_on(to_sq(m))] >= PieceValue[Mg][piece_moved(m)])
       return 1;
 
   return see(m);
@@ -1270,7 +1256,7 @@ int Position::see(Move m) const {
   stm = ~color_of(piece_on(from));
   stmAttackers = attackers & pieces(stm);
   if (!stmAttackers)
-      return PieceValueMidgame[capturedType];
+      return PieceValue[Mg][capturedType];
 
   // The destination square is defended, which makes things rather more
   // difficult to compute. We proceed by building up a "swap list" containing
@@ -1278,7 +1264,7 @@ int Position::see(Move m) const {
   // destination square, where the sides alternately capture, and always
   // capture with the least valuable piece. After each capture, we look for
   // new X-ray attacks from behind the capturing piece.
-  swapList[0] = PieceValueMidgame[capturedType];
+  swapList[0] = PieceValue[Mg][capturedType];
   capturedType = type_of(piece_on(from));
 
   do {
@@ -1299,7 +1285,7 @@ int Position::see(Move m) const {
 
       // Add the new entry to the swap list
       assert(slIndex < 32);
-      swapList[slIndex] = -swapList[slIndex - 1] + PieceValueMidgame[capturedType];
+      swapList[slIndex] = -swapList[slIndex - 1] + PieceValue[Mg][capturedType];
       slIndex++;
 
       // Remember the value of the capturing piece, and change the side to
@@ -1312,7 +1298,7 @@ int Position::see(Move m) const {
       if (capturedType == KING && stmAttackers)
       {
           assert(slIndex < 32);
-          swapList[slIndex++] = QueenValueMidgame*10;
+          swapList[slIndex++] = QueenValueMg * 16;
           break;
       }
   } while (stmAttackers);
@@ -1454,7 +1440,7 @@ Value Position::compute_non_pawn_material(Color c) const {
   Value value = VALUE_ZERO;
 
   for (PieceType pt = KNIGHT; pt <= QUEEN; pt++)
-      value += piece_count(c, pt) * PieceValueMidgame[pt];
+      value += piece_count(c, pt) * PieceValue[Mg][pt];
 
   return value;
 }
@@ -1468,7 +1454,7 @@ bool Position::is_draw() const {
 
   // Draw by material?
   if (   !pieces(PAWN)
-      && (non_pawn_material(WHITE) + non_pawn_material(BLACK) <= BishopValueMidgame))
+      && (non_pawn_material(WHITE) + non_pawn_material(BLACK) <= BishopValueMg))
       return true;
 
   // Draw by the 50 moves rule?
index a29fd0f64772e9ae7048a52973697f5da99f7fc5..6586144dfabceac40f269567244d192c98702d04 100644 (file)
@@ -159,7 +159,7 @@ namespace {
         &&  type_of(pos.piece_on(to_sq(m))) != PAWN
         &&  type_of(m) == NORMAL
         && (  pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
-            - PieceValueMidgame[pos.piece_on(to_sq(m))] == VALUE_ZERO))
+            - PieceValue[Mg][pos.piece_on(to_sq(m))] == VALUE_ZERO))
         return true;
 
     return false;
@@ -688,7 +688,7 @@ namespace {
         Depth R = 3 * ONE_PLY + depth / 4;
 
         // Null move dynamic reduction based on value
-        if (refinedValue - PawnValueMidgame > beta)
+        if (refinedValue - PawnValueMg > beta)
             R += ONE_PLY;
 
         pos.do_null_move<true>(st);
@@ -1176,7 +1176,7 @@ split_point_start: // At split points actual search starts from here
             alpha = bestValue;
 
         futilityBase = ss->eval + evalMargin + FutilityMarginQS;
-        enoughMaterial = pos.non_pawn_material(pos.side_to_move()) > RookValueMidgame;
+        enoughMaterial = pos.non_pawn_material(pos.side_to_move()) > RookValueMg;
     }
 
     // Initialize a MovePicker object for the current position, and prepare
@@ -1204,8 +1204,8 @@ split_point_start: // At split points actual search starts from here
           && !pos.is_passed_pawn_push(move))
       {
           futilityValue =  futilityBase
-                         + PieceValueEndgame[pos.piece_on(to_sq(move))]
-                         + (type_of(move) == ENPASSANT ? PawnValueEndgame : VALUE_ZERO);
+                         + PieceValue[Eg][pos.piece_on(to_sq(move))]
+                         + (type_of(move) == ENPASSANT ? PawnValueEg : VALUE_ZERO);
 
           if (futilityValue < beta)
           {
@@ -1243,7 +1243,7 @@ split_point_start: // At split points actual search starts from here
           &&  givesCheck
           &&  move != ttMove
           && !pos.is_capture_or_promotion(move)
-          &&  ss->eval + PawnValueMidgame / 4 < beta
+          &&  ss->eval + PawnValueMg / 4 < beta
           && !check_is_dangerous(pos, move, futilityBase, beta))
           continue;
 
@@ -1328,7 +1328,7 @@ split_point_start: // At split points actual search starts from here
     while (b)
     {
         // Note that here we generate illegal "double move"!
-        if (futilityBase + PieceValueEndgame[pos.piece_on(pop_lsb(&b))] >= beta)
+        if (futilityBase + PieceValue[Eg][pos.piece_on(pop_lsb(&b))] >= beta)
             return true;
     }
 
@@ -1440,7 +1440,7 @@ split_point_start: // At split points actual search starts from here
     // Case 2: If the threatened piece has value less than or equal to the
     // value of the threatening piece, don't prune moves which defend it.
     if (   pos.is_capture(threat)
-        && (   PieceValueMidgame[pos.piece_on(tfrom)] >= PieceValueMidgame[pos.piece_on(tto)]
+        && (   PieceValue[Mg][pos.piece_on(tfrom)] >= PieceValue[Mg][pos.piece_on(tto)]
             || type_of(pos.piece_on(tfrom)) == KING)
         && pos.move_attacks_square(m, tto))
         return true;
@@ -1500,7 +1500,7 @@ split_point_start: // At split points actual search starts from here
 
     // RootMoves are already sorted by score in descending order
     size_t size = std::min(MultiPV, RootMoves.size());
-    int variance = std::min(RootMoves[0].score - RootMoves[size - 1].score, PawnValueMidgame);
+    int variance = std::min(RootMoves[0].score - RootMoves[size - 1].score, PawnValueMg);
     int weakness = 120 - 2 * SkillLevel;
     int max_s = -VALUE_INFINITE;
     Move best = MOVE_NONE;
index d67b2eea63a411bcda7fccfdc55ec26b2438ea97..ce73cab2964c9ecf618adf6fd46ef24b0b3255d2 100644 (file)
@@ -168,16 +168,13 @@ enum Value {
   VALUE_ENSURE_INTEGER_SIZE_P = INT_MAX,
   VALUE_ENSURE_INTEGER_SIZE_N = INT_MIN,
 
-  PawnValueMidgame   = 198,
-  PawnValueEndgame   = 258,
-  KnightValueMidgame = 817,
-  KnightValueEndgame = 846,
-  BishopValueMidgame = 836,
-  BishopValueEndgame = 857,
-  RookValueMidgame   = 1270,
-  RookValueEndgame   = 1278,
-  QueenValueMidgame  = 2521,
-  QueenValueEndgame  = 2558
+  Mg = 0, Eg = 1,
+
+  PawnValueMg   = 198,   PawnValueEg   = 258,
+  KnightValueMg = 817,   KnightValueEg = 846,
+  BishopValueMg = 836,   BishopValueEg = 857,
+  RookValueMg   = 1270,  RookValueEg   = 1278,
+  QueenValueMg  = 2521,  QueenValueEg  = 2558
 };
 
 enum PieceType {
@@ -323,7 +320,7 @@ inline Score apply_weight(Score v, Score w) {
 
 namespace Zobrist {
 
-  extern Key psq[2][8][64]; // [color][pieceType][square]/[piece count]
+  extern Key psq[2][8][64]; // [color][pieceType][square / piece count]
   extern Key enpassant[8];  // [file]
   extern Key castle[16];    // [castleRight]
   extern Key side;
@@ -332,10 +329,11 @@ namespace Zobrist {
   void init();
 }
 
-extern Score pieceSquareTable[16][64];
-extern int SquareDistance[64][64];
-extern const Value PieceValueMidgame[17]; // Indexed by Piece or PieceType
-extern const Value PieceValueEndgame[17];
+CACHE_LINE_ALIGNMENT
+
+extern Score pieceSquareTable[16][64]; // [piece][square]
+extern Value PieceValue[2][18];        // [Mg / Eg][piece / pieceType]
+extern int SquareDistance[64][64];     // [square][square]
 
 struct MoveStack {
   Move move;