-////
-//// Includes
-////
-
-#include "position.h"
-
-
-////
-//// Prototypes
-////
-
-extern int generate_captures(const Position& pos, MoveStack* mlist);
-extern int generate_noncaptures(const Position& pos, MoveStack* mlist);
-extern int generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc);
-extern int generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned);
-extern int generate_legal_moves(const Position& pos, MoveStack* mlist);
-extern bool move_is_legal(const Position& pos, const Move m, Bitboard pinned);
-
+#include "move.h"
+
+enum MoveType {
+ MV_CAPTURE,
+ MV_NON_CAPTURE,
+ MV_CHECK,
+ MV_NON_CAPTURE_CHECK,
+ MV_EVASION,
+ MV_NON_EVASION,
+ MV_LEGAL
+};
+
+template<MoveType>
+MoveStack* generate(const Position& pos, MoveStack* mlist);
+
+/// The MoveList struct is a simple wrapper around generate(), sometimes comes
+/// handy to use this class instead of the low level generate() function.
+template<MoveType T>
+struct MoveList {
+
+ explicit MoveList(const Position& pos) : cur(mlist), last(generate<T>(pos, mlist)) {}
+ void operator++() { cur++; }
+ bool end() const { return cur == last; }
+ Move move() const { return cur->move; }
+ int size() const { return int(last - mlist); }
+
+private:
+ MoveStack mlist[MAX_MOVES];
+ MoveStack *cur, *last;
+};