-#include "ucioption.h"
-
-#ifdef USE_CALLGRIND
-#include <valgrind/callgrind.h>
-#endif
-
-using std::string;
-
-////
-//// Functions
-////
-
-int main(int argc, char *argv[]) {
-
- // Disable IO buffering
- std::cout.rdbuf()->pubsetbuf(NULL, 0);
- std::cin.rdbuf()->pubsetbuf(NULL, 0);
-
- // Initialization
- init_mersenne();
- init_direction_table();
- init_bitboards();
- init_uci_options();
- Position::init_zobrist();
- Position::init_piece_square_tables();
- MovePicker::init_phase_table();
- init_eval(1);
- init_bitbases();
- init_threads();
-
-#ifdef USE_CALLGRIND
- CALLGRIND_START_INSTRUMENTATION;
-#endif
-
- // Make random number generation less deterministic, for book moves
- for (int i = abs(get_system_time() % 10000); i > 0; i--)
- genrand_int32();
-
- // Process command line arguments
- if (argc >= 2 && string(argv[1]) == "bench")
- {
- if (argc < 4 || argc > 7)
- {
- std::cout << "Usage: stockfish bench <hash size> <threads> "
- << "[time = 60s] [fen positions file = default] "
- << "[time, depth or node limited = time]"
- << std::endl;
- exit(0);
- }
- string time = argc > 4 ? argv[4] : "60";
- string fen = argc > 5 ? argv[5] : "default";
- string lim = argc > 6 ? argv[6] : "time";
- benchmark(string(argv[2]) + " " + string(argv[3]) + " " + time + " " + fen + " " + lim);
- return 0;
- }
-
- // Print copyright notice
- std::cout << engine_name() << ". Copyright (C) "
- << "2004-2008 Tord Romstad, Marco Costalba. "
- << std::endl;
-
- // Enter UCI mode
- uci_main_loop();
+#include "syzygy/tbprobe.h"
+
+#include <grpc/grpc.h>
+#include <grpc++/server.h>
+#include <grpc++/server_builder.h>
+#include "hashprobe.grpc.pb.h"
+
+using grpc::Server;
+using grpc::ServerBuilder;
+using grpc::ServerContext;
+using grpc::Status;
+using grpc::StatusCode;
+
+class HashProbeImpl final : public HashProbe::Service {
+public:
+ Status Probe(ServerContext* context,
+ const HashProbeRequest* request,
+ HashProbeResponse *response) {
+ std::cout << "fen=" << request->fen() << std::endl;
+ Position pos(request->fen(), /*isChess960=*/false, Threads.main());
+ if (!pos.pos_is_ok()) {
+ return Status(StatusCode::INVALID_ARGUMENT, "Invalid FEN");
+ }
+ std::cout << "parsed=" << pos.fen() << std::endl;
+ bool found;
+ TTEntry *entry = TT.probe(pos.key(), found);
+ response->set_found(found);
+ if (found) {
+ response->set_move(entry->move());
+ response->set_value(entry->value());
+ response->set_eval(entry->eval());
+ response->set_depth(entry->depth());
+ response->set_bound(entry->bound());
+ }
+ return Status::OK;
+ }
+};
+
+void rpc_thread()
+{
+ std::string server_address("0.0.0.0:50051");
+ HashProbeImpl service;
+
+ ServerBuilder builder;
+ builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
+ builder.RegisterService(&service);
+ std::unique_ptr<Server> server(builder.BuildAndStart());
+ std::cout << "Server listening on " << server_address << std::endl;
+ server->Wait();
+}
+
+namespace PSQT {
+ void init();
+}
+
+int main(int argc, char* argv[]) {
+
+ std::cout << engine_info() << std::endl;
+
+ UCI::init(Options);
+ PSQT::init();
+ Bitboards::init();
+ Position::init();
+ Bitbases::init();
+ Search::init();
+ Pawns::init();
+ Threads.set(Options["Threads"]);
+ Search::clear(); // After threads are up
+
+ std::thread(&rpc_thread).detach();
+
+ UCI::loop(argc, argv);