1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

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.
This commit is contained in:
Marco Costalba 2015-01-31 18:39:51 +01:00
parent 81d6c4a0d6
commit 65f46794af
5 changed files with 15 additions and 13 deletions

View 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;
}

View 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;
}

View 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

View 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;
}

View 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;