]> git.sesse.net Git - stockfish/commitdiff
Implicit conversion from ExtMove to Move
authorMarco Costalba <mcostalba@gmail.com>
Sat, 31 Jan 2015 17:39:51 +0000 (18:39 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 31 Jan 2015 18:22:07 +0000 (19:22 +0100)
Verified with perft there is no speed regression,
and code is simpler. It is also conceptually correct
becuase an extended move is just a move that happens
to have also a score.

No functional change.

src/movegen.h
src/search.cpp
src/thread.cpp
src/uci.cpp
src/ucioption.cpp

index 6f1e24a4313107680c0508bd9a95722a3773af0d..d46b8ddb7c9b4d5021fdbbcd13ff5dd59d2872ca 100644 (file)
@@ -36,6 +36,8 @@ enum GenType {
 struct ExtMove {
   Move move;
   Value value;
+
+  operator Move() const { return move; }
 };
 
 inline bool operator<(const ExtMove& f, const ExtMove& s) {
@@ -54,8 +56,8 @@ struct MoveList {
   const ExtMove* begin() const { return moveList; }
   const ExtMove* end() const { return last; }
   size_t size() const { return last - moveList; }
-  bool contains(Move m) const {
-    for (const ExtMove& ms : *this) if (ms.move == m) return true;
+  bool contains(Move move) const {
+    for (const auto& m : *this) if (m == move) return true;
     return false;
   }
 
index 450df57539ca9349ded64dd855f8f7eae50f22bf..34fcc17637211029366f6868bb0bcf8d392cb971 100644 (file)
@@ -152,19 +152,19 @@ uint64_t Search::perft(Position& pos, Depth depth) {
   CheckInfo ci(pos);
   const bool leaf = (depth == 2 * ONE_PLY);
 
-  for (const ExtMove& ms : MoveList<LEGAL>(pos))
+  for (const auto& m : MoveList<LEGAL>(pos))
   {
       if (Root && depth <= ONE_PLY)
           cnt = 1, nodes++;
       else
       {
-          pos.do_move(ms.move, st, ci, pos.gives_check(ms.move, ci));
+          pos.do_move(m, st, ci, pos.gives_check(m, ci));
           cnt = leaf ? MoveList<LEGAL>(pos).size() : perft<false>(pos, depth - ONE_PLY);
           nodes += cnt;
-          pos.undo_move(ms.move);
+          pos.undo_move(m);
       }
       if (Root)
-          sync_cout << UCI::move(ms.move, pos.is_chess960()) << ": " << cnt << sync_endl;
+          sync_cout << UCI::move(m, pos.is_chess960()) << ": " << cnt << sync_endl;
   }
   return nodes;
 }
index c232b849babacc66ef6e262322678b18883a37e5..c25fc129cd4ef0bc570e9377ecfe63765e8fb294 100644 (file)
@@ -365,10 +365,10 @@ void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
       assert(!states.get());
   }
 
-  for (const ExtMove& ms : MoveList<LEGAL>(pos))
+  for (const auto& m : MoveList<LEGAL>(pos))
       if (   limits.searchmoves.empty()
-          || std::count(limits.searchmoves.begin(), limits.searchmoves.end(), ms.move))
-          RootMoves.push_back(RootMove(ms.move));
+          || std::count(limits.searchmoves.begin(), limits.searchmoves.end(), m))
+          RootMoves.push_back(RootMove(m));
 
   main()->thinking = true;
   main()->notify_one(); // Starts main thread
index f05a114e51993088df0c20cc2b86dda2bbc5436f..ff3a64ece151aafe690695445066494cbee25d1d 100644 (file)
@@ -272,9 +272,9 @@ Move UCI::to_move(const Position& pos, string& str) {
   if (str.length() == 5) // Junior could send promotion piece in uppercase
       str[4] = char(tolower(str[4]));
 
-  for (const ExtMove& ms : MoveList<LEGAL>(pos))
-      if (str == UCI::move(ms.move, pos.is_chess960()))
-          return ms.move;
+  for (const auto& m : MoveList<LEGAL>(pos))
+      if (str == UCI::move(m, pos.is_chess960()))
+          return m;
 
   return MOVE_NONE;
 }
index c78237641d061a3fa513722f13188d573165bc80..06641cf5081908aa04c804b4ba2e75c022cc2db2 100644 (file)
@@ -81,7 +81,7 @@ void init(OptionsMap& o) {
 std::ostream& operator<<(std::ostream& os, const OptionsMap& om) {
 
   for (size_t idx = 0; idx < om.size(); ++idx)
-      for (auto& it : om)
+      for (const auto& it : om)
           if (it.second.idx == idx)
           {
               const Option& o = it.second;