stellarUCI Chess engine written in C++20 |
git clone git://git.dimitrijedobrota.com/stellar.git |
Log | Files | Refs | README | LICENSE | |
movelist.hpp (1055B)
1 #ifndef STELLAR_MOVE_LIST_H 2 #define STELLAR_MOVE_LIST_H 3 4 #include "board.hpp" 5 #include "move.hpp" 6 #include "utils.hpp" 7 8 #include <iostream> 9 #include <numeric> 10 #include <vector> 11 12 class MoveList { 13 private: 14 using list_t = std::vector<Move>; 15 16 public: 17 MoveList() : list(){}; 18 MoveList(const Board &board, bool attacks_only = false, bool legal = false) : list() { 19 list.reserve(256); 20 generate(board, attacks_only); 21 if (!legal) return; 22 23 int size = 0; 24 for (int i = 0; i < list.size(); i++) { 25 Board copy = board; 26 if (list[i].make(copy)) list[size++] = list[i]; 27 } 28 list.resize(size); 29 } 30 31 void clear() { list.clear(); } 32 int size() const { return list.size(); } 33 34 const Move operator[](size_t idx) const { return list[idx]; } 35 void push(const Move move) { list.push_back(move); } 36 37 friend std::ostream &operator<<(std::ostream &os, const MoveList &list); 38 39 private: 40 void generate(const Board &board, bool attacks_only); 41 42 list_t list; 43 }; 44 45 #endif