]> git.sesse.net Git - stockfish/blobdiff - src/position.h
Unify compute_mg_value() and compute_eg_value()
[stockfish] / src / position.h
index 1e7dc9926ba24eb80e67c182bd5678ad710de89a..11b9e2de13991e75fc2d94c28d5123dfded556dd 100644 (file)
@@ -74,17 +74,16 @@ enum CastleRights {
 
 
 /// The UndoInfo struct stores information we need to restore a Position
-/// object to its previous state when we retract a move.  Whenever a move
+/// object to its previous state when we retract a move. Whenever a move
 /// is made on the board (by calling Position::do_move), an UndoInfo object
-/// must be passed as a parameter.  When the move is unmade (by calling
+/// must be passed as a parameter. When the move is unmade (by calling
 /// Position::undo_move), the same UndoInfo object must be passed again.
 
 struct UndoInfo {
-  int castleRights;
-  Square epSquare;
-  Bitboard checkersBB, pinners[2], pinned[2], dcCandidates[2];
+  Bitboard pinners[2], pinned[2], dcCandidates[2], checkersBB;
   Key key, pawnKey, materialKey;
-  int rule50;
+  int castleRights, rule50;
+  Square epSquare;
   Move lastMove;
   Value mgValue, egValue;
   PieceType capture;
@@ -221,7 +220,6 @@ public:
   // Properties of moves
   bool pl_move_is_legal(Move m) const;
   bool move_is_check(Move m) const;
-  bool move_is_check(Move m, Bitboard dcCandidates) const;
   bool move_is_capture(Move m) const;
   bool move_is_deep_pawn_push(Move m) const;
   bool move_is_pawn_push_to_7th(Move m) const;
@@ -242,10 +240,7 @@ public:
   bool square_is_weak(Square s, Color c) const;
 
   // Doing and undoing moves
-  void backup(UndoInfo &u) const;
-  void restore(const UndoInfo &u);
   void do_move(Move m, UndoInfo &u);
-  void do_move(Move m, UndoInfo &u, Bitboard dcCandidates);
   void undo_move(Move m, const UndoInfo &u);
   void do_null_move(UndoInfo &u);
   void undo_null_move(const UndoInfo &u);
@@ -320,16 +315,17 @@ private:
   Key compute_material_key() const;
 
   // Computing incremental evaluation scores and material counts
+  enum GamePhase {
+      MidGame,
+      EndGame
+  };
   Value mg_pst(Color c, PieceType pt, Square s) const;
   Value eg_pst(Color c, PieceType pt, Square s) const;
-  Value compute_mg_value() const;
-  Value compute_eg_value() const;
+  Value compute_value(GamePhase p) const;
   Value compute_non_pawn_material(Color c) const;
 
   // Bitboards
   Bitboard byColorBB[2], byTypeBB[8];
-  Bitboard checkersBB;
-  mutable Bitboard pinners[2], pinned[2], dcCandidates[2];
 
   // Board
   Piece board[64];
@@ -342,16 +338,27 @@ private:
   int index[64];
 
   // Other info
-  Color sideToMove;
-  int castleRights;
-  File initialKFile, initialKRFile, initialQRFile;
-  Square epSquare;
   Square kingSquare[2];
-  Move lastMove;
-  Key key, pawnKey, materialKey, history[MaxGameLength];
-  int rule50, gamePly;
-  Value mgValue, egValue;
+  Color sideToMove;
+  int gamePly;
+  Key history[MaxGameLength];
   Value npMaterial[2];
+  File initialKFile, initialKRFile, initialQRFile;
+
+  // Info backed up in do_move()
+  union {
+      UndoInfo undoInfoUnion;
+      struct { // Must have the same layout of UndoInfo
+          mutable Bitboard pinners[2], pinned[2], dcCandidates[2];
+          Bitboard checkersBB;
+          Key key, pawnKey, materialKey;
+          int castleRights, rule50;
+          Square epSquare;
+          Move lastMove;
+          Value mgValue, egValue;
+          PieceType capture;
+      };
+  };
 
   // Static variables
   static int castleRightsMask[64];