]> git.sesse.net Git - stockfish/commitdiff
Mimic an iterator for looping across MoveList
authorMarco Costalba <mcostalba@gmail.com>
Sun, 19 May 2013 11:28:25 +0000 (13:28 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 19 May 2013 11:28:25 +0000 (13:28 +0200)
Seems more conventional.

No functional change.

src/book.cpp
src/movegen.h
src/notation.cpp
src/position.cpp
src/search.cpp
src/thread.cpp

index b8bce9e1d07ba3e6630ee9e8746f5294187bc46a..b906d766779ae8fbd391ef2d99b066dd44428ee4 100644 (file)
@@ -436,9 +436,9 @@ Move PolyglotBook::probe(const Position& pos, const string& fName, bool pickBest
       move = make<PROMOTION>(from_sq(move), to_sq(move), PieceType(pt + 1));
 
   // Add 'special move' flags and verify it is legal
-  for (MoveList<LEGAL> ml(pos); !ml.end(); ++ml)
-      if (move == (ml.move() ^ type_of(ml.move())))
-          return ml.move();
+  for (MoveList<LEGAL> it(pos); !it.end(); ++it)
+      if (move == (*it ^ type_of(*it)))
+          return *it;
 
   return MOVE_NONE;
 }
index c96e73cfd07d2d53d9c70a1d4658490ed708b7fa..9db23dd407c1d23e35d03cb4874040005c3b931b 100644 (file)
@@ -43,8 +43,8 @@ struct MoveList {
 
   explicit MoveList(const Position& pos) : cur(mlist), last(generate<T>(pos, mlist)) {}
   void operator++() { cur++; }
+  Move operator*() const { return cur->move; }
   bool end() const { return cur == last; }
-  Move move() const { return cur->move; }
   size_t size() const { return last - mlist; }
   bool contains(Move m) const {
     for (const MoveStack* it(mlist); it != last; ++it) if (it->move == m) return true;
index 2b4174ef0e5f817f9bbcb215cd140d247a06aa7c..0a97d9fd2ba04706e9e686a4fba7788762cd2e5e 100644 (file)
@@ -89,9 +89,9 @@ Move move_from_uci(const Position& pos, string& str) {
   if (str.length() == 5) // Junior could send promotion piece in uppercase
       str[4] = char(tolower(str[4]));
 
-  for (MoveList<LEGAL> ml(pos); !ml.end(); ++ml)
-      if (str == move_to_uci(ml.move(), pos.is_chess960()))
-          return ml.move();
+  for (MoveList<LEGAL> it(pos); !it.end(); ++it)
+      if (str == move_to_uci(*it, pos.is_chess960()))
+          return *it;
 
   return MOVE_NONE;
 }
index 210a1ba9d7ad09358800770c89de02d4a90ed966..80130fec97e961bdd201a94e81cca8045c8a95a5 100644 (file)
@@ -408,8 +408,8 @@ const string Position::pretty(Move move) const {
       ss << square_to_string(pop_lsb(&b)) << " ";
 
   ss << "\nLegal moves: ";
-  for (MoveList<LEGAL> ml(*this); !ml.end(); ++ml)
-      ss << move_to_san(*const_cast<Position*>(this), ml.move()) << " ";
+  for (MoveList<LEGAL> it(*this); !it.end(); ++it)
+      ss << move_to_san(*const_cast<Position*>(this), *it) << " ";
 
   return ss.str();
 }
index 238631fabaef6bb4d0f621ed21203f906358aed4..a7c169ac1af1832945c8100e99c2d44bfe6fca3b 100644 (file)
@@ -163,11 +163,11 @@ size_t Search::perft(Position& pos, Depth depth) {
   size_t cnt = 0;
   CheckInfo ci(pos);
 
-  for (MoveList<LEGAL> ml(pos); !ml.end(); ++ml)
+  for (MoveList<LEGAL> it(pos); !it.end(); ++it)
   {
-      pos.do_move(ml.move(), st, ci, pos.move_gives_check(ml.move(), ci));
+      pos.do_move(*it, st, ci, pos.move_gives_check(*it, ci));
       cnt += perft(pos, depth - ONE_PLY);
-      pos.undo_move(ml.move());
+      pos.undo_move(*it);
   }
 
   return cnt;
index f5b8b5e275aff3313b74ae061fd8b4455d98dab8..71b9ce0c091412e6424791c1e38bd4553fc04f7c 100644 (file)
@@ -371,10 +371,10 @@ void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
   SetupStates = states; // Ownership transfer here
   RootMoves.clear();
 
-  for (MoveList<LEGAL> ml(pos); !ml.end(); ++ml)
+  for (MoveList<LEGAL> it(pos); !it.end(); ++it)
       if (   searchMoves.empty()
-          || std::count(searchMoves.begin(), searchMoves.end(), ml.move()))
-          RootMoves.push_back(RootMove(ml.move()));
+          || std::count(searchMoves.begin(), searchMoves.end(), *it))
+          RootMoves.push_back(RootMove(*it));
 
   main_thread()->thinking = true;
   main_thread()->notify_one(); // Starts main thread