Make the client prober output something a bit more easily parseable, and run in a...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 17 Mar 2016 01:12:13 +0000 (02:12 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 24 Nov 2018 10:17:41 +0000 (11:17 +0100)
src/Makefile
src/client.cpp

index 2e8a492..cd79223 100644 (file)
@@ -40,7 +40,7 @@ OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
        material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o \
        search.o thread.o timeman.o tt.o uci.o ucioption.o syzygy/tbprobe.o \
        hashprobe.grpc.pb.o hashprobe.pb.o
-CLIOBJS = client.o hashprobe.grpc.pb.o hashprobe.pb.o
+CLIOBJS = client.o hashprobe.grpc.pb.o hashprobe.pb.o uci.o
 
 ### Establish the operating system name
 KERNEL = $(shell uname -s)
index 05fe597..02980b8 100644 (file)
@@ -5,6 +5,8 @@
 #include <grpc++/grpc++.h>
 
 #include "hashprobe.grpc.pb.h"
+#include "types.h"
+#include "uci.h"
 
 using grpc::Channel;
 using grpc::ClientContext;
@@ -15,18 +17,42 @@ int main(int argc, char** argv) {
       "localhost:50051", grpc::InsecureChannelCredentials()));
   std::unique_ptr<HashProbe::Stub> stub(HashProbe::NewStub(channel));
 
-  HashProbeRequest request;
-//  request.set_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
-  request.set_fen(argv[1]);
-
-  HashProbeResponse response;
-  ClientContext context;
-  Status status = stub->Probe(&context, request, &response);
-
-  if (status.ok()) {
-    std::cout << response.DebugString();
-  } else {
-    std::cout << "RPC failed";
+  for ( ;; ) {
+    char buf[256];
+    if (fgets(buf, sizeof(buf), stdin) == nullptr || buf[0] == '\n') {
+      exit(0);
+    }
+
+    char *ptr = strchr(buf, '\n');
+    if (ptr != nullptr) *ptr = 0;
+
+    HashProbeRequest request;
+    request.set_fen(buf);
+
+    HashProbeResponse response;
+    ClientContext context;
+    Status status = stub->Probe(&context, request, &response);
+
+    if (status.ok()) {
+      std::cout << response.found() << " "
+                << UCI::square(from_sq(Move(response.move())))
+                << UCI::square(to_sq(Move(response.move()))) << " ";
+      switch (response.bound()) {
+      case HashProbeResponse::BOUND_NONE:
+      case HashProbeResponse::BOUND_EXACT:
+        break;
+      case HashProbeResponse::BOUND_UPPER:
+        std::cout << "<=";
+        break;
+      case HashProbeResponse::BOUND_LOWER:
+        std::cout << ">=";
+        break;
+      } 
+      std::cout << UCI::value(Value(response.value())) << " ";
+      std::cout << response.depth() << std::endl;
+    } else {
+      std::cout << "ERROR" << std::endl;
+    }
   }
 
   return 0;