5 #include <grpc++/grpc++.h>
7 #include "hashprobe.grpc.pb.h"
12 using grpc::ClientContext;
14 using namespace hashprobe;
16 std::string FormatMove(const HashProbeMove &move) {
17 if (move.from_sq().empty()) return "MOVE_NONE";
21 int main(int argc, char** argv) {
22 std::shared_ptr<Channel> channel(grpc::CreateChannel(
23 "localhost:50051", grpc::InsecureChannelCredentials()));
24 std::unique_ptr<HashProbe::Stub> stub(HashProbe::NewStub(channel));
28 if (fgets(buf, sizeof(buf), stdin) == nullptr || buf[0] == '\n') {
32 char *ptr = strchr(buf, '\n');
33 if (ptr != nullptr) *ptr = 0;
35 HashProbeRequest request;
38 HashProbeResponse response;
39 ClientContext context;
40 Status status = stub->Probe(&context, request, &response);
43 for (const HashProbeLine &line : response.line()) {
44 std::cout << FormatMove(line.move()) << " ";
45 std::cout << line.found() << " ";
46 for (const HashProbeMove &move : line.pv()) {
47 std::cout << FormatMove(move) << ",";
50 switch (line.bound()) {
51 case HashProbeLine::BOUND_NONE:
54 case HashProbeLine::BOUND_EXACT:
57 case HashProbeLine::BOUND_UPPER:
60 case HashProbeLine::BOUND_LOWER:
64 switch (line.value().score_type()) {
65 case HashProbeScore::SCORE_CP:
66 std::cout << " cp " << line.value().score_cp() << " ";
68 case HashProbeScore::SCORE_MATE:
69 std::cout << " mate " << line.value().score_mate() << " ";
72 std::cout << line.depth() << std::endl;
74 std::cout << "END" << std::endl;
76 std::cout << "ERROR" << std::endl;