aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp42
-rw-r--r--src/uci.cpp31
2 files changed, 31 insertions, 42 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 27b428d..e7f2d87 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,48 +7,11 @@
#include <string>
#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 <non-negative depth> <fen>\n";
- exit(1);
- }
-
- uint32_t depth = 0;
- try {
- depth = static_cast<uint32_t>(std::stoi(argv[2]));
- } catch (const std::exception &) {
- std::cout << "info string usage: ./mono perft <non-negative depth>\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<std::chrono::milliseconds>(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 <fen> [moves...]\n";
@@ -79,11 +42,6 @@ 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;
diff --git a/src/uci.cpp b/src/uci.cpp
index 7cff997..5f62169 100644
--- a/src/uci.cpp
+++ b/src/uci.cpp
@@ -1,6 +1,7 @@
#include <array>
#include <cassert>
#include <cctype>
+#include <chrono>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
@@ -351,5 +352,35 @@ void Uci() {
uint64_t hash = GenerateHashFromScratch(&game);
std::cout << hash << "\n";
}
+ if (cmd.starts_with("perft")) {
+
+ uint32_t depth = 0;
+
+ std::stringstream ss(cmd);
+ std::string token;
+
+ ss >> token; // position
+
+ ss >> depth;
+
+ auto start = std::chrono::steady_clock::now();
+
+ 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<std::chrono::milliseconds>(end - start)
+ .count();
+ std::ostringstream oss;
+ oss << "{\"ms\": " << ms << ", \"result\": " << count << "}";
+
+ std::cout << oss.str() << "\n";
+ }
}
}