stellar

UCI Chess engine written in C++20
git clone git://git.dimitrijedobrota.com/stellar.git
Log | Files | Refs | README | LICENSE

movelist.hpp (1166B)


0 #ifndef STELLAR_MOVE_LIST_H
1 #define STELLAR_MOVE_LIST_H
3 #include "board.hpp"
4 #include "move.hpp"
5 #include "utils.hpp"
7 #include <iostream>
8 #include <numeric>
9 #include <vector>
11 class MoveList {
12 private:
13 using list_t = std::vector<Move>;
15 public:
16 MoveList() : list(){};
17 MoveList(const Board &board, bool attacks_only = false) : list() {
18 list.reserve(256);
19 generate(board, attacks_only);
20 }
22 MoveList(const Board &board, bool attacks_only, bool legal) : MoveList(board, attacks_only) {
23 int size = 0;
24 for (const auto &move : list) {
25 Board copy = board;
26 if (move.make(copy)) list[size++] = move;
27 }
28 list.resize(size);
29 }
31 void clear() { list.clear(); }
32 [[nodiscard]] int size() const { return list.size(); }
34 const Move operator[](size_t idx) const { return list[idx]; }
35 Move &operator[](size_t idx) { return list[idx]; }
36 void push(const Move move) { list.push_back(move); }
38 friend std::ostream &operator<<(std::ostream &os, const MoveList &list);
40 private:
41 void generate(const Board &board, bool attacks_only);
43 list_t list;
44 };
46 #endif