From: Marco Costalba Date: Sat, 31 Jan 2015 17:39:51 +0000 (+0100) Subject: Implicit conversion from ExtMove to Move X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=65f46794af41534e0dc744c6f7531a4c43eca857 Implicit conversion from ExtMove to Move 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. --- diff --git a/src/movegen.h b/src/movegen.h index 6f1e24a4..d46b8ddb 100644 --- a/src/movegen.h +++ b/src/movegen.h @@ -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; } diff --git a/src/search.cpp b/src/search.cpp index 450df575..34fcc176 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -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(pos)) + for (const auto& m : MoveList(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(pos).size() : perft(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; } diff --git a/src/thread.cpp b/src/thread.cpp index c232b849..c25fc129 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -365,10 +365,10 @@ void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits, assert(!states.get()); } - for (const ExtMove& ms : MoveList(pos)) + for (const auto& m : MoveList(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 diff --git a/src/uci.cpp b/src/uci.cpp index f05a114e..ff3a64ec 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -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(pos)) - if (str == UCI::move(ms.move, pos.is_chess960())) - return ms.move; + for (const auto& m : MoveList(pos)) + if (str == UCI::move(m, pos.is_chess960())) + return m; return MOVE_NONE; } diff --git a/src/ucioption.cpp b/src/ucioption.cpp index c7823764..06641cf5 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -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;