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
3 #include <cstdint>
4 #include <queue>
5 #include <string>
7 class Engine {
8 public:
9 Engine(const Engine &) = delete;
10 Engine &operator=(const Engine &) = delete;
11 Engine(const char *file);
13 ~Engine();
15 [[nodiscard]] const std::string &get_name() const { return name; }
16 [[nodiscard]] const std::string &get_author() const { return author; }
18 void send(std::string &&command);
19 std::string receive();
21 private:
22 class Pipes {
23 public:
24 Pipes();
25 Pipes(const Pipes &) = delete;
26 Pipes &operator=(const Pipes &) = delete;
28 ~Pipes() {
29 if (!closed) close();
30 }
32 void close();
34 int operator[](int idx) { return fd[idx]; }
36 private:
37 int fd[2]{};
38 bool closed = false;
39 };
41 [[noreturn]] void start_engine();
43 const char *file = nullptr;
44 Pipes pipeFrom, pripeTo;
45 pid_t engine_pid;
47 std::string name, author;
49 char rb[1000]{};
50 int rb_size = 0;
52 std::queue<std::string> q;
53 std::string q_buffer;
55 static uint16_t id_t;
56 uint16_t id = id_t++;
57 };
59 #endif