X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmain.cpp;h=6c1aa034c318e9802c9e082d4db2394cc0ded307;hp=a093b5bf0a234d644f1f15a34c0329c0008322a4;hb=d963529dcaa3ba80267aaca8b769a3081d2c5da9;hpb=bb58bc215c93a17cd6ee672eac5495b48e9f3d22 diff --git a/src/main.cpp b/src/main.cpp index a093b5bf..6c1aa034 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,7 @@ */ #include +#include #include "bitboard.h" #include "position.h" @@ -28,6 +29,55 @@ #include "uci.h" #include "syzygy/tbprobe.h" +#include +#include +#include +#include "hashprobe.grpc.pb.h" + +using grpc::Server; +using grpc::ServerBuilder; +using grpc::ServerContext; +using grpc::Status; +using grpc::StatusCode; + +class HashProbeImpl final : public HashProbe::Service { +public: + Status Probe(ServerContext* context, + const HashProbeRequest* request, + HashProbeResponse *response) { + std::cout << "fen=" << request->fen() << std::endl; + Position pos(request->fen(), /*isChess960=*/false, Threads.main()); + if (!pos.pos_is_ok()) { + return Status(StatusCode::INVALID_ARGUMENT, "Invalid FEN"); + } + std::cout << "parsed=" << pos.fen() << std::endl; + bool found; + TTEntry *entry = TT.probe(pos.key(), found); + response->set_found(found); + if (found) { + response->set_move(entry->move()); + response->set_value(entry->value()); + response->set_eval(entry->eval()); + response->set_depth(entry->depth()); + response->set_bound(entry->bound()); + } + return Status::OK; + } +}; + +void rpc_thread() +{ + std::string server_address("0.0.0.0:50051"); + HashProbeImpl service; + + ServerBuilder builder; + builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); + builder.RegisterService(&service); + std::unique_ptr server(builder.BuildAndStart()); + std::cout << "Server listening on " << server_address << std::endl; + server->Wait(); +} + namespace PSQT { void init(); } @@ -46,6 +96,8 @@ int main(int argc, char* argv[]) { Threads.set(Options["Threads"]); Search::clear(); // After threads are up + std::thread(&rpc_thread).detach(); + UCI::loop(argc, argv); Threads.set(0);