stellar

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

engine.hpp (1169B)


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