stellar

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

movelist.hpp (1055B)


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, bool legal = false) : list() {
18 list.reserve(256);
19 generate(board, attacks_only);
20 if (!legal) return;
22 int size = 0;
23 for (int i = 0; i < list.size(); i++) {
24 Board copy = board;
25 if (list[i].make(copy)) list[size++] = list[i];
26 }
27 list.resize(size);
28 }
30 void clear() { list.clear(); }
31 int size() const { return list.size(); }
33 const Move operator[](size_t idx) const { return list[idx]; }
34 void push(const Move move) { list.push_back(move); }
36 friend std::ostream &operator<<(std::ostream &os, const MoveList &list);
38 private:
39 void generate(const Board &board, bool attacks_only);
41 list_t list;
42 };
44 #endif