stellarUCI Chess engine written in C++20 |
git clone git://git.dimitrijedobrota.com/stellar.git |
Log | Files | Refs | README | LICENSE |
engine.hpp (1169B)
0 #ifndef STELLAR_ARENA_ENGINE_H 1 #define STELLAR_ARENA_ENGINE_H 2 3 #include <cstdint> 4 #include <queue> 5 #include <string> 6 7 class Engine { 8 public: 9 Engine(const Engine &) = delete; 10 Engine &operator=(const Engine &) = delete; 11 Engine(const char *file); 12 13 ~Engine(); 14 15 [[nodiscard]] const std::string &get_name() const { return name; } 16 [[nodiscard]] const std::string &get_author() const { return author; } 17 18 void send(std::string &&command); 19 std::string receive(); 20 21 private: 22 class Pipes { 23 public: 24 Pipes(); 25 Pipes(const Pipes &) = delete; 26 Pipes &operator=(const Pipes &) = delete; 27 28 ~Pipes() { 29 if (!closed) close(); 30 } 31 32 void close(); 33 34 int operator[](int idx) { return fd[idx]; } 35 36 private: 37 int fd[2]{}; 38 bool closed = false; 39 }; 40 41 [[noreturn]] void start_engine(); 42 43 const char *file = nullptr; 44 Pipes pipeFrom, pripeTo; 45 pid_t engine_pid; 46 47 std::string name, author; 48 49 char rb[1000]{}; 50 int rb_size = 0; 51 52 std::queue<std::string> q; 53 std::string q_buffer; 54 55 static uint16_t id_t; 56 uint16_t id = id_t++; 57 }; 58 59 #endif