+#include "thread.h"
+#include "tt.h"
+#include "uci.h"
+#include "syzygy/tbprobe.h"
+
+#include <grpc/grpc.h>
+#include <grpc++/server.h>
+#include <grpc++/server_builder.h>
+#include "hashprobe.grpc.pb.h"
+
+using grpc::Server;
+using grpc::ServerBuilder;
+using grpc::ServerContext;
+using grpc::Status;
+using grpc::StatusCode;
+using namespace hashprobe;
+
+class HashProbeImpl final : public HashProbe::Service {
+public:
+ Status Probe(ServerContext* context,
+ const HashProbeRequest* request,
+ HashProbeResponse *response) {
+ Position pos(request->fen(), /*isChess960=*/false, Threads.main());
+ if (!pos.pos_is_ok()) {
+ return Status(StatusCode::INVALID_ARGUMENT, "Invalid FEN");
+ }
+
+ bool invert = (pos.side_to_move() == BLACK);
+
+ HashProbeMove *root_move = response->add_move();
+ root_move->set_move(MOVE_NONE);
+ ProbeMove(pos.key(), invert, root_move);
+
+ MoveList<LEGAL> moves(pos);
+ for (const ExtMove* em = moves.begin(); em != moves.end(); ++em) {
+ HashProbeMove *move = response->add_move();
+ move->set_move(em->move);
+ ProbeMove(pos.key_after(em->move), !invert, move);
+ }