#include <grpc++/grpc++.h>
#include "hashprobe.grpc.pb.h"
+#include "types.h"
+#include "uci.h"
using grpc::Channel;
using grpc::ClientContext;
using grpc::Status;
+using namespace hashprobe;
+
+std::string FormatMove(Move move) {
+ if (move == MOVE_NULL) {
+ return "Null-move";
+ } else if (move == MOVE_NONE) {
+ return "MOVE_NONE";
+ } else {
+ return UCI::square(from_sq(move)) + UCI::square(to_sq(move));
+ }
+}
int main(int argc, char** argv) {
std::shared_ptr<Channel> channel(grpc::CreateChannel(
"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]);
+ for ( ;; ) {
+ char buf[256];
+ if (fgets(buf, sizeof(buf), stdin) == nullptr || buf[0] == '\n') {
+ exit(0);
+ }
- HashProbeResponse response;
- ClientContext context;
- Status status = stub->Probe(&context, request, &response);
+ char *ptr = strchr(buf, '\n');
+ if (ptr != nullptr) *ptr = 0;
- if (status.ok()) {
- std::cout << response.DebugString();
- } else {
- std::cout << "RPC failed";
+ HashProbeRequest request;
+ request.set_fen(buf);
+
+ HashProbeResponse response;
+ ClientContext context;
+ Status status = stub->Probe(&context, request, &response);
+
+ if (status.ok()) {
+ for (const HashProbeMove &hpmove : response.move()) {
+ std::cout << FormatMove(Move(hpmove.move())) << " ";
+ std::cout << hpmove.found() << " ";
+ std::cout << FormatMove(Move(hpmove.pv_move())) << " ";
+ switch (hpmove.bound()) {
+ case HashProbeMove::BOUND_NONE:
+ std::cout << "?";
+ break;
+ case HashProbeMove::BOUND_EXACT:
+ std::cout << "==";
+ break;
+ case HashProbeMove::BOUND_UPPER:
+ std::cout << "<=";
+ break;
+ case HashProbeMove::BOUND_LOWER:
+ std::cout << ">=";
+ break;
+ }
+ std::cout << " " << UCI::value(Value(hpmove.value())) << " ";
+ std::cout << hpmove.depth() << std::endl;
+ }
+ std::cout << "END" << std::endl;
+ } else {
+ std::cout << "ERROR" << std::endl;
+ }
}
return 0;