X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovegen.h;h=d46b8ddb7c9b4d5021fdbbcd13ff5dd59d2872ca;hp=62a121d7d291629e37aeebe32afe32fbc29776c6;hb=519b2fe849760d3cab5cce9ef9dc3cd076bd300d;hpb=4eb2d8ce095b284a1e55762548d9821a83a19b3b diff --git a/src/movegen.h b/src/movegen.h index 62a121d7..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) { @@ -50,18 +52,17 @@ ExtMove* generate(const Position& pos, ExtMove* moveList); template struct MoveList { - explicit MoveList(const Position& pos) : cur(moveList), last(generate(pos, moveList)) { last->move = MOVE_NONE; } - void operator++() { ++cur; } - Move operator*() const { return cur->move; } + explicit MoveList(const Position& pos) : last(generate(pos, 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* it(moveList); it != last; ++it) if (it->move == m) return true; + bool contains(Move move) const { + for (const auto& m : *this) if (m == move) return true; return false; } private: - ExtMove moveList[MAX_MOVES]; - ExtMove *cur, *last; + ExtMove moveList[MAX_MOVES], *last; }; #endif // #ifndef MOVEGEN_H_INCLUDED