]> git.sesse.net Git - stockfish/blob - src/client.cpp
Do not use -Wshadow; it is incredibly noisy for protobuf code.
[stockfish] / src / client.cpp
1 #include <iostream>
2 #include <memory>
3 #include <string>
4
5 #include <grpc++/grpc++.h>
6
7 #include "hashprobe.grpc.pb.h"
8 #include "types.h"
9 #include "uci.h"
10
11 using grpc::Channel;
12 using grpc::ClientContext;
13 using grpc::Status;
14
15 int main(int argc, char** argv) {
16   std::shared_ptr<Channel> channel(grpc::CreateChannel(
17       "localhost:50051", grpc::InsecureChannelCredentials()));
18   std::unique_ptr<HashProbe::Stub> stub(HashProbe::NewStub(channel));
19
20   for ( ;; ) {
21     char buf[256];
22     if (fgets(buf, sizeof(buf), stdin) == nullptr || buf[0] == '\n') {
23       exit(0);
24     }
25
26     char *ptr = strchr(buf, '\n');
27     if (ptr != nullptr) *ptr = 0;
28
29     HashProbeRequest request;
30     request.set_fen(buf);
31
32     HashProbeResponse response;
33     ClientContext context;
34     Status status = stub->Probe(&context, request, &response);
35
36     if (status.ok()) {
37       std::cout << response.found() << " ";
38       if (Move(response.move()) == MOVE_NULL) {
39         std::cout << "Null-move ";
40       } else if (Move(response.move()) == MOVE_NONE) {
41         std::cout << "MOVE_NONE ";
42       } else {
43         std::cout << UCI::square(from_sq(Move(response.move())))
44                   << UCI::square(to_sq(Move(response.move()))) << " ";
45       }
46       switch (response.bound()) {
47       case HashProbeResponse::BOUND_NONE:
48         std::cout << "?";
49         break;
50       case HashProbeResponse::BOUND_EXACT:
51         std::cout << "==";
52         break;
53       case HashProbeResponse::BOUND_UPPER:
54         std::cout << "<=";
55         break;
56       case HashProbeResponse::BOUND_LOWER:
57         std::cout << ">=";
58         break;
59       } 
60       std::cout << " " << UCI::value(Value(response.value())) << " ";
61       std::cout << response.depth() << std::endl;
62     } else {
63       std::cout << "ERROR" << std::endl;
64     }
65   }
66
67   return 0;
68 }