From 8ceef922662c75c33d105d99732475c125b01081 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 19 May 2013 13:28:25 +0200 Subject: [PATCH 1/1] Mimic an iterator for looping across MoveList Seems more conventional. No functional change. --- src/book.cpp | 6 +++--- src/movegen.h | 2 +- src/notation.cpp | 6 +++--- src/position.cpp | 4 ++-- src/search.cpp | 6 +++--- src/thread.cpp | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/book.cpp b/src/book.cpp index b8bce9e1..b906d766 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -436,9 +436,9 @@ Move PolyglotBook::probe(const Position& pos, const string& fName, bool pickBest move = make(from_sq(move), to_sq(move), PieceType(pt + 1)); // Add 'special move' flags and verify it is legal - for (MoveList ml(pos); !ml.end(); ++ml) - if (move == (ml.move() ^ type_of(ml.move()))) - return ml.move(); + for (MoveList it(pos); !it.end(); ++it) + if (move == (*it ^ type_of(*it))) + return *it; return MOVE_NONE; } diff --git a/src/movegen.h b/src/movegen.h index c96e73cf..9db23dd4 100644 --- a/src/movegen.h +++ b/src/movegen.h @@ -43,8 +43,8 @@ struct MoveList { explicit MoveList(const Position& pos) : cur(mlist), last(generate(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; diff --git a/src/notation.cpp b/src/notation.cpp index 2b4174ef..0a97d9fd 100644 --- a/src/notation.cpp +++ b/src/notation.cpp @@ -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 ml(pos); !ml.end(); ++ml) - if (str == move_to_uci(ml.move(), pos.is_chess960())) - return ml.move(); + for (MoveList it(pos); !it.end(); ++it) + if (str == move_to_uci(*it, pos.is_chess960())) + return *it; return MOVE_NONE; } diff --git a/src/position.cpp b/src/position.cpp index 210a1ba9..80130fec 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -408,8 +408,8 @@ const string Position::pretty(Move move) const { ss << square_to_string(pop_lsb(&b)) << " "; ss << "\nLegal moves: "; - for (MoveList ml(*this); !ml.end(); ++ml) - ss << move_to_san(*const_cast(this), ml.move()) << " "; + for (MoveList it(*this); !it.end(); ++it) + ss << move_to_san(*const_cast(this), *it) << " "; return ss.str(); } diff --git a/src/search.cpp b/src/search.cpp index 238631fa..a7c169ac 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -163,11 +163,11 @@ size_t Search::perft(Position& pos, Depth depth) { size_t cnt = 0; CheckInfo ci(pos); - for (MoveList ml(pos); !ml.end(); ++ml) + for (MoveList 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; diff --git a/src/thread.cpp b/src/thread.cpp index f5b8b5e2..71b9ce0c 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -371,10 +371,10 @@ void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits, SetupStates = states; // Ownership transfer here RootMoves.clear(); - for (MoveList ml(pos); !ml.end(); ++ml) + for (MoveList 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 -- 2.39.2