]> git.sesse.net Git - stockfish/commitdiff
Passing UndoInfo is not needed anymore when undoing the move
authorMarco Costalba <mcostalba@gmail.com>
Sun, 22 Feb 2009 16:49:52 +0000 (17:49 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 22 Feb 2009 20:18:02 +0000 (21:18 +0100)
We store it now in the same UndoInfo struct as 'previous'
field, so when doing a move we also know where to get
the previous info when undoing the back the move.

This is needed for future patches and is a nice cleanup anyway.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/position.cpp
src/position.h
src/search.cpp

index 435384cf93740bea491d47e4f3112e39dd5abe8d..21b00f80536d45cd3fedd9784b7f3bbca1017089 100644 (file)
@@ -706,6 +706,7 @@ void Position::do_move(Move m, UndoInfo& u) {
   // captured piece, which is taken care of later.
   u = undoInfoUnion;
   u.capture = NO_PIECE_TYPE;
+  previous = &u;
 
   // Save the current key to the history[] array, in order to be able to
   // detect repetition draws.
@@ -722,7 +723,7 @@ void Position::do_move(Move m, UndoInfo& u) {
   if (move_is_castle(m))
       do_castle_move(m);
   else if (move_promotion(m))
-      do_promotion_move(m, u);
+      do_promotion_move(m);
   else if (move_is_ep(m))
       do_ep_move(m);
   else
@@ -977,7 +978,7 @@ void Position::do_castle_move(Move m) {
 /// UndoInfo object, which has been initialized in Position::do_move, is
 /// used to store the captured piece (if any).
 
-void Position::do_promotion_move(Move m, UndoInfo &u) {
+void Position::do_promotion_move(Move m) {
 
   Color us, them;
   Square from, to;
@@ -1000,7 +1001,7 @@ void Position::do_promotion_move(Move m, UndoInfo &u) {
 
   if (capture)
   {
-    u.capture = capture;
+    previous->capture = capture;
     do_capture_move(m, capture, them, to);
   }
 
@@ -1156,7 +1157,7 @@ void Position::do_ep_move(Move m) {
 /// important that Position::undo_move is called with the same move and UndoInfo
 /// object as the earlier call to Position::do_move.
 
-void Position::undo_move(Move m, const UndoInfo &u) {
+void Position::undo_move(Move m) {
 
   assert(is_ok());
   assert(move_is_ok(m));
@@ -1166,19 +1167,19 @@ void Position::undo_move(Move m, const UndoInfo &u) {
 
   // Restore information from our UndoInfo object (except the captured piece,
   // which is taken care of later)
-  undoInfoUnion = u;
+  undoInfoUnion = *previous;
 
   if (move_is_castle(m))
       undo_castle_move(m);
   else if (move_promotion(m))
-      undo_promotion_move(m, u);
+      undo_promotion_move(m);
   else if (move_is_ep(m))
       undo_ep_move(m);
   else
   {
       Color us, them;
       Square from, to;
-      PieceType piece, capture;
+      PieceType piece;
 
       us = side_to_move();
       them = opposite_color(us);
@@ -1208,8 +1209,6 @@ void Position::undo_move(Move m, const UndoInfo &u) {
       pieceList[us][piece][index[to]] = from;
       index[from] = index[to];
 
-      capture = u.capture;
-
       if (capture)
       {
           assert(capture != KING);
@@ -1309,11 +1308,11 @@ void Position::undo_castle_move(Move m) {
 /// function. The UndoInfo object, which has been initialized in
 /// Position::do_move, is used to put back the captured piece (if any).
 
-void Position::undo_promotion_move(Move m, const UndoInfo &u) {
+void Position::undo_promotion_move(Move m) {
 
   Color us, them;
   Square from, to;
-  PieceType capture, promotion;
+  PieceType promotion;
 
   assert(move_is_ok(m));
   assert(move_promotion(m));
@@ -1357,8 +1356,6 @@ void Position::undo_promotion_move(Move m, const UndoInfo &u) {
   pieceCount[us][promotion]--;
   pieceCount[us][PAWN]++;
 
-  capture = u.capture;
-
   if (capture)
   {
       assert(capture != KING);
@@ -1686,6 +1683,7 @@ void Position::clear() {
   epSquare = SQ_NONE;
   rule50 = 0;
   gamePly = 0;
+  previous = NULL;
 }
 
 
@@ -1939,7 +1937,7 @@ bool Position::has_mate_threat(Color c) {
       if (is_mate())
           result = true;
 
-      undo_move(mlist[i].move, u2);
+      undo_move(mlist[i].move);
   }
 
   // Undo null move, if necessary
index f3bb011274e04616809c4b82018047c19d17c4d8..c132c8f88a5bb56c576108f2486ca66dad38997d 100644 (file)
@@ -87,6 +87,7 @@ struct UndoInfo {
   Move lastMove;
   Value mgValue, egValue;
   PieceType capture;
+  UndoInfo* previous;
 };
 
 
@@ -241,7 +242,7 @@ public:
 
   // Doing and undoing moves
   void do_move(Move m, UndoInfo &u);
-  void undo_move(Move m, const UndoInfo &u);
+  void undo_move(Move m);
   void do_null_move(UndoInfo &u);
   void undo_null_move(const UndoInfo &u);
 
@@ -296,10 +297,10 @@ private:
   // Helper functions for doing and undoing moves
   void do_capture_move(Move m, PieceType capture, Color them, Square to);
   void do_castle_move(Move m);
-  void do_promotion_move(Move m, UndoInfo &u);
+  void do_promotion_move(Move m);
   void do_ep_move(Move m);
   void undo_castle_move(Move m);
-  void undo_promotion_move(Move m, const UndoInfo &u);
+  void undo_promotion_move(Move m);
   void undo_ep_move(Move m);
   void find_checkers();
 
@@ -356,6 +357,7 @@ private:
           Move lastMove;
           Value mgValue, egValue;
           PieceType capture;
+          UndoInfo* previous;
       };
   };
 
index 6e210c0f2f086e219e0f3f217c229cc00c1b6050..3b81fa86dae57f154d2a41df79620c14a0e6bfb5 100644 (file)
@@ -835,7 +835,7 @@ namespace {
             }
         }
 
-        pos.undo_move(move, u);
+        pos.undo_move(move);
 
         // Finished searching the move. If AbortSearch is true, the search
         // was aborted because the user interrupted the search or because we
@@ -1054,7 +1054,7 @@ namespace {
           }
         }
       }
-      pos.undo_move(move, u);
+      pos.undo_move(move);
 
       assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
 
@@ -1358,7 +1358,7 @@ namespace {
           ss[ply].reduction = Depth(0);
           value = -search(pos, ss, -(beta-1), newDepth, ply+1, true, threadID);
       }
-      pos.undo_move(move, u);
+      pos.undo_move(move);
 
       assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
 
@@ -1516,7 +1516,7 @@ namespace {
       UndoInfo u;
       pos.do_move(move, u);
       Value value = -qsearch(pos, ss, -beta, -alpha, depth-OnePly, ply+1, threadID);
-      pos.undo_move(move, u);
+      pos.undo_move(move);
 
       assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
 
@@ -1628,7 +1628,7 @@ namespace {
           ss[sp->ply].reduction = Depth(0);
           value = -search(pos, ss, -(sp->beta - 1), newDepth, sp->ply+1, true, threadID);
       }
-      pos.undo_move(move, u);
+      pos.undo_move(move);
 
       assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
 
@@ -1751,7 +1751,7 @@ namespace {
               Threads[threadID].failHighPly1 = false;
         }
       }
-      pos.undo_move(move, u);
+      pos.undo_move(move);
 
       assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
 
@@ -1884,7 +1884,7 @@ namespace {
             pos.do_move(moves[count].move, u);
             moves[count].score = -qsearch(pos, ss, -VALUE_INFINITE, VALUE_INFINITE,
                                           Depth(0), 1, 0);
-            pos.undo_move(moves[count].move, u);
+            pos.undo_move(moves[count].move);
             moves[count].pv[0] = moves[i].move;
             moves[count].pv[1] = MOVE_NONE; // FIXME
             count++;