]> git.sesse.net Git - stockfish/blobdiff - src/position.h
Explicitly use delta psqt values when possible
[stockfish] / src / position.h
index ed9b8edcc6ff0ac7c20e8ce951060b0be0c83ab9..9730d3dc24b253d276fdb8ffe2e0771cc91a8087 100644 (file)
@@ -91,6 +91,7 @@ struct StateInfo {
   int castleRights, rule50;
   Square epSquare;
   Value mgValue, egValue;
+  Value npMaterial[2];
 
   PieceType capture;
   Bitboard checkersBB;
@@ -126,6 +127,11 @@ class Position {
   friend class EndgameFunctions;
 
 public:
+  enum GamePhase {
+      MidGame,
+      EndGame
+  };
+
   // Constructors
   Position() {};
   Position(const Position& pos);
@@ -137,8 +143,8 @@ public:
   void print(Move m = MOVE_NONE) const;
 
   // Copying
-  void copy(const Position &pos);
-  void flipped_copy(const Position &pos);
+  void copy(const Positionpos);
+  void flipped_copy(const Positionpos);
 
   // The piece on a given square
   Piece piece_on(Square s) const;
@@ -249,7 +255,7 @@ public:
   bool square_is_weak(Square s, Color c) const;
 
   // Doing and undoing moves
-  void setStartState(const StateInfo& st);
+  void saveState();
   void do_move(Move m, StateInfo& st);
   void do_move(Move m, StateInfo& st, Bitboard dcCandidates);
   void undo_move(Move m);
@@ -271,7 +277,7 @@ public:
   Value eg_value() const;
   Value non_pawn_material(Color c) const;
   Phase game_phase() const;
-  Value mg_pst_delta(Move m) const;
+  template<GamePhase> Value pst_delta(Piece piece, Square from, Square to) const;
 
   // Game termination checks
   bool is_mate() const;
@@ -327,10 +333,6 @@ private:
   Key compute_material_key() const;
 
   // Computing incremental evaluation scores and material counts
-  enum GamePhase {
-      MidGame,
-      EndGame
-  };
   template<GamePhase> Value pst(Color c, PieceType pt, Square s) const;
   template<GamePhase> Value compute_value() const;
   Value compute_non_pawn_material(Color c) const;
@@ -353,7 +355,6 @@ private:
   Color sideToMove;
   int gamePly;
   Key history[MaxGameLength];
-  Value npMaterial[2];
   File initialKFile, initialKRFile, initialQRFile;
   StateInfo startState;
   StateInfo* st;
@@ -494,10 +495,6 @@ inline Bitboard Position::bishops_and_queens(Color c) const {
   return bishops_and_queens() & pieces_of_color(c);
 }
 
-inline Bitboard Position::sliders_of_color(Color c) const {
-  return sliders() & pieces_of_color(c);
-}
-
 inline int Position::piece_count(Color c, PieceType pt) const {
   return pieceCount[c][pt];
 }
@@ -538,14 +535,14 @@ inline Bitboard Position::pawn_attacks(Color c, Square s) const {
   return StepAttackBB[piece_of_color_and_type(c, PAWN)][s];
 }
 
-template<>
-inline Bitboard Position::piece_attacks<PAWN>(Square s) const {
-  return StepAttackBB[piece_of_color_and_type(opposite_color(sideToMove), PAWN)][s];
+template<PieceType Piece> // Knight and King
+inline Bitboard Position::piece_attacks(Square s) const {
+  return StepAttackBB[Piece][s];
 }
 
 template<>
-inline Bitboard Position::piece_attacks<KNIGHT>(Square s) const {
-  return StepAttackBB[KNIGHT][s];
+inline Bitboard Position::piece_attacks<PAWN>(Square s) const {
+  return StepAttackBB[piece_of_color_and_type(opposite_color(sideToMove), PAWN)][s];
 }
 
 template<>
@@ -563,11 +560,6 @@ inline Bitboard Position::piece_attacks<QUEEN>(Square s) const {
   return piece_attacks<ROOK>(s) | piece_attacks<BISHOP>(s);
 }
 
-template<>
-inline Bitboard Position::piece_attacks<KING>(Square s) const {
-  return StepAttackBB[KING][s];
-}
-
 inline Bitboard Position::checkers() const {
   return st->checkersBB;
 }
@@ -631,15 +623,16 @@ inline Key Position::get_material_key() const {
   return st->materialKey;
 }
 
-template<Position::GamePhase Phase>
+template<Position::GamePhase Ph>
 inline Value Position::pst(Color c, PieceType pt, Square s) const {
-  return (Phase == MidGame ? MgPieceSquareTable[piece_of_color_and_type(c, pt)][s]
-                           : EgPieceSquareTable[piece_of_color_and_type(c, pt)][s]);
+  return (Ph == MidGame ? MgPieceSquareTable[piece_of_color_and_type(c, pt)][s]
+                        : EgPieceSquareTable[piece_of_color_and_type(c, pt)][s]);
 }
 
-inline Value Position::mg_pst_delta(Move m) const {
-  return MgPieceSquareTable[piece_on(move_from(m))][move_to(m)]
-        -MgPieceSquareTable[piece_on(move_from(m))][move_from(m)];
+template<Position::GamePhase Ph>
+inline Value Position::pst_delta(Piece piece, Square from, Square to) const {
+  return (Ph == MidGame ? MgPieceSquareTable[piece][to] - MgPieceSquareTable[piece][from]
+                        : EgPieceSquareTable[piece][to] - EgPieceSquareTable[piece][from]);
 }
 
 inline Value Position::mg_value() const {
@@ -651,7 +644,7 @@ inline Value Position::eg_value() const {
 }
 
 inline Value Position::non_pawn_material(Color c) const {
-  return npMaterial[c];
+  return st->npMaterial[c];
 }
 
 inline Phase Position::game_phase() const {