]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Reformat piece values arrays
[stockfish] / src / position.cpp
index 60bdeafb4ca7d6b4e2d5db620b61cdf76f852ab9..21022ae1b2c18dc7655eef0460d80cd3bdc054db 100644 (file)
@@ -36,35 +36,18 @@ using std::string;
 using std::cout;
 using std::endl;
 
 using std::cout;
 using std::endl;
 
-// To convert a Piece to and from a FEN char
 static const string PieceToChar(" PNBRQK  pnbrqk");
 
 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
 
 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 {
 
 
 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;
 Key enpassant[8];  // [file]
 Key castle[16];    // [castleRight]
 Key side;
@@ -103,7 +86,10 @@ void init() {
 
   for (PieceType pt = PAWN; pt <= KING; pt++)
   {
 
   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++)
       {
 
       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->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;
 
       // 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
                          - pieceSquareTable[make_piece(us, PAWN)][to];
 
           // Update material
-          st->npMaterial[us] += PieceValueMidgame[promotion];
+          st->npMaterial[us] += PieceValue[Mg][promotion];
       }
 
       // Update pawn hash key
       }
 
       // 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.
   // 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);
       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)
   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
 
   // 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.
   // 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 {
   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);
 
       // 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
       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);
       if (capturedType == KING && stmAttackers)
       {
           assert(slIndex < 32);
-          swapList[slIndex++] = QueenValueMidgame*10;
+          swapList[slIndex++] = QueenValueMg * 16;
           break;
       }
   } while (stmAttackers);
           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 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;
 }
 
   return value;
 }
@@ -1468,7 +1454,7 @@ bool Position::is_draw() const {
 
   // Draw by material?
   if (   !pieces(PAWN)
 
   // 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?
       return true;
 
   // Draw by the 50 moves rule?