From: Steinar H. Gunderson Date: Thu, 17 Mar 2016 01:12:13 +0000 (+0100) Subject: Make the client prober output something a bit more easily parseable, and run in a... X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=c20b7d555559440987abee142e3dade9a664bb00 Make the client prober output something a bit more easily parseable, and run in a loop. --- diff --git a/src/Makefile b/src/Makefile index 2e8a4928..cd79223a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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) diff --git a/src/client.cpp b/src/client.cpp index 05fe5972..02980b8d 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -5,6 +5,8 @@ #include #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 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;