#include #include #include #include #include #include #include #include "board/board.hpp" #include "board/fen.hpp" #include "hash.hpp" #include "misc.hpp" #include "moves.hpp" #include "uci.hpp" static void perft(int argc, char *argv[]) { if (argc < 4 || std::string(argv[1]) != "perft") { std::cout << "Usage: ./mono\n"; std::cout << " ./mono perft \n"; exit(1); } uint32_t depth = 0; try { depth = static_cast(std::stoi(argv[2])); } catch (const std::exception &) { std::cout << "info string usage: ./mono perft \n"; exit(1); } std::string fen = argv[3]; auto start = std::chrono::steady_clock::now(); Game game = initBoard(fen, nullptr); uint64_t count = 0; #ifdef PERFT_DIVIDE count = MoveGenTestDivide(depth, &game); #else count = MoveGenTest(depth, &game); #endif auto end = std::chrono::steady_clock::now(); auto ms = std::chrono::duration_cast(end - start) .count(); std::ostringstream oss; oss << "{\"ms\": " << ms << ", \"result\": " << count << "}"; std::cout << oss.str() << "\n"; } static void hashCmd(int argc, char *argv[]) { if (argc < 3) { std::cout << "Usage: ./mono hash [moves...]\n"; exit(1); } std::string fen = argv[2]; Game game = initBoard(fen, nullptr); for (int i = 3; i < argc; ++i) { uint16_t move = UciToMove(argv[i]); MakeMove(move, &game); } auto start = std::chrono::steady_clock::now(); uint64_t hash = GenerateHashFromScratch(&game); auto end = std::chrono::steady_clock::now(); auto ms = std::chrono::duration_cast(end - start) .count(); std::ostringstream oss; oss << "{\"ms\": " << ms << ", \"hash\": " << hash << "}"; std::cout << oss.str() << "\n"; } int main(int argc, char *argv[]) { InitHashing(); initMagicBitboards(); if (argc >= 2 && std::string(argv[1]) == "perft") { perft(argc, argv); return 0; } if (argc >= 2 && std::string(argv[1]) == "hash") { hashCmd(argc, argv); return 0; } if (argc != 1) { std::cout << "Usage: ./mono \n"; return 0; } std::cerr << engine_info(); Uci(); return 0; }