]> git.sesse.net Git - stockfish/commitdiff
Use st->gamePly to store fullMoves
authorMarco Costalba <mcostalba@gmail.com>
Wed, 20 Jul 2011 08:01:12 +0000 (10:01 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 24 Jul 2011 05:15:36 +0000 (06:15 +0100)
This allow to retire do_setup_move() and also to simplify
draw detection logic becuase now we always have:

Min(st->rule50, st->gamePly) = st->rule50

This was already true when starting from starting position,
but now is true even when starting from a FEN string because
now we take in account fullmove number in counting gamePly so
that it is always.

st->rule50 <= st->gamePly

No functional change.

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

index 28fa369548b12d3a8b30e7a214d3374a622f4ac8..bc9b5e0e2f6c1905d4739b2741b220aec1255d5f 100644 (file)
@@ -190,7 +190,11 @@ void Position::from_fen(const string& fenStr, bool isChess960) {
   }
 
   // 5-6. Halfmove clock and fullmove number
   }
 
   // 5-6. Halfmove clock and fullmove number
-  fen >> std::skipws >> st->rule50 >> fullMoves;
+  fen >> std::skipws >> st->rule50 >> st->gamePly;
+
+  // Convert from fullmove starting from 1 to ply starting from 0,
+  // handle also common incorrect FEN with fullmove = 0.
+  st->gamePly = Max(2 * (st->gamePly - 1), 0) + int(sideToMove == BLACK);
 
   // Various initialisations
   chess960 = isChess960;
 
   // Various initialisations
   chess960 = isChess960;
@@ -310,7 +314,7 @@ const string Position::to_fen() const {
       fen << '-';
 
   fen << (ep_square() == SQ_NONE ? " -" : " " + square_to_string(ep_square()))
       fen << '-';
 
   fen << (ep_square() == SQ_NONE ? " -" : " " + square_to_string(ep_square()))
-      << " " << st->rule50 << " " << fullMoves;
+      << " " << st->rule50 << " " << 1 + (st->gamePly - int(sideToMove == BLACK)) / 2;
 
   return fen.str();
 }
 
   return fen.str();
 }
@@ -759,23 +763,6 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
 }
 
 
 }
 
 
-/// Position::do_setup_move() makes a permanent move on the board. It should
-/// be used when setting up a position on board. You can't undo the move.
-
-void Position::do_setup_move(Move m, StateInfo& newSt) {
-
-  assert(move_is_ok(m));
-
-  // Update the number of full moves after black's move
-  if (sideToMove == BLACK)
-      fullMoves++;
-
-  do_move(m, newSt);
-
-  assert(is_ok());
-}
-
-
 /// Position::do_move() makes a move, and saves all information necessary
 /// to a StateInfo object. The move is assumed to be legal. Pseudo-legal
 /// moves should be filtered out before this function is called.
 /// Position::do_move() makes a move, and saves all information necessary
 /// to a StateInfo object. The move is assumed to be legal. Pseudo-legal
 /// moves should be filtered out before this function is called.
@@ -1528,7 +1515,6 @@ void Position::clear() {
       castleRightsMask[sq] = ALL_CASTLES;
   }
   sideToMove = WHITE;
       castleRightsMask[sq] = ALL_CASTLES;
   }
   sideToMove = WHITE;
-  fullMoves = 1;
   nodes = 0;
 }
 
   nodes = 0;
 }
 
@@ -1670,7 +1656,7 @@ bool Position::is_draw() const {
   // Draw by repetition?
   if (!SkipRepetition)
   {
   // Draw by repetition?
   if (!SkipRepetition)
   {
-      int i = 4, e = Min(Min(st->gamePly, st->rule50), st->pliesFromNull);
+      int i = 4, e = Min(st->rule50, st->pliesFromNull);
 
       if (i <= e)
       {
 
       if (i <= e)
       {
index 431d059c7efb2570305b752807dc10ac60c2266e..14e6b95c3136fd7dc14be38b9359df3aa980ad33 100644 (file)
@@ -163,7 +163,6 @@ public:
   bool pawn_is_passed(Color c, Square s) const;
 
   // Doing and undoing moves
   bool pawn_is_passed(Color c, Square s) const;
 
   // Doing and undoing moves
-  void do_setup_move(Move m, StateInfo& st);
   void do_move(Move m, StateInfo& st);
   void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
   void undo_move(Move m);
   void do_move(Move m, StateInfo& st);
   void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
   void undo_move(Move m);
@@ -190,7 +189,7 @@ public:
   template<bool SkipRepetition> bool is_draw() const;
 
   // Number of plies from starting position
   template<bool SkipRepetition> bool is_draw() const;
 
   // Number of plies from starting position
-  int startpos_ply_counter() const;
+  int game_ply() const;
 
   // Other properties of the position
   bool opposite_colored_bishops() const;
 
   // Other properties of the position
   bool opposite_colored_bishops() const;
@@ -257,7 +256,6 @@ private:
   StateInfo startState;
   int64_t nodes;
   Color sideToMove;
   StateInfo startState;
   int64_t nodes;
   Color sideToMove;
-  int fullMoves;
   int threadID;
   StateInfo* st;
   int chess960;
   int threadID;
   StateInfo* st;
   int chess960;
@@ -423,8 +421,8 @@ inline bool Position::move_is_passed_pawn_push(Move m) const {
         && pawn_is_passed(c, move_to(m));
 }
 
         && pawn_is_passed(c, move_to(m));
 }
 
-inline int Position::startpos_ply_counter() const {
-  return Max(2 * (fullMoves - 1), 0) + int(sideToMove == BLACK);
+inline int Position::game_ply() const {
+  return st->gamePly;
 }
 
 inline bool Position::opposite_colored_bishops() const {
 }
 
 inline bool Position::opposite_colored_bishops() const {
index aec6434553a8c82f48908fad4183ed20ea50121d..29f573851186dda19a072f32127bc3418ec125a1 100644 (file)
@@ -393,7 +393,7 @@ bool think(Position& pos, const SearchLimits& limits, Move searchMoves[]) {
   NodesSincePoll = 0;
   current_search_time(get_system_time());
   Limits = limits;
   NodesSincePoll = 0;
   current_search_time(get_system_time());
   Limits = limits;
-  TimeMgr.init(Limits, pos.startpos_ply_counter());
+  TimeMgr.init(Limits, pos.game_ply());
 
   // Set output steram in normal or chess960 mode
   cout << set960(pos.is_chess960());
 
   // Set output steram in normal or chess960 mode
   cout << set960(pos.is_chess960());
index fb24bb264c9235cc0f4742afcf52763906ac71f3..b17cf08920c0a10eddf5c1d1b5d1818c2bb34861 100644 (file)
@@ -144,13 +144,13 @@ namespace {
     }
     else return;
 
     }
     else return;
 
-    // Parse move list (if any)
     SetupState.clear();
 
     SetupState.clear();
 
+    // Parse move list (if any)
     while (up >> token && (m = move_from_uci(pos, token)) != MOVE_NONE)
     {
         SetupState.push_back(StateInfo());
     while (up >> token && (m = move_from_uci(pos, token)) != MOVE_NONE)
     {
         SetupState.push_back(StateInfo());
-        pos.do_setup_move(m, SetupState.back());
+        pos.do_move(m, SetupState.back());
     }
   }
 
     }
   }