aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-08-10 15:04:16 +0200
committerAdam <adammegarules1@gmail.com>2026-08-10 15:04:16 +0200
commit6a39e28205d44e96da72728c0a3d4d6468962539 (patch)
tree8c9685dbe7b82edd7fc3068a51ff41e2e4d0be07 /src
parent775368b3596d8d1c376d7b783a1b6faf9db7f7ef (diff)
adding json based perft tests
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp54
-rw-r--r--src/uci.cpp25
2 files changed, 51 insertions, 28 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 4469e40..a2af33f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,13 +1,61 @@
+#include <cassert>
+#include <chrono>
+#include <cstdint>
+#include <cstdlib>
+#include <iostream>
+#include <sstream>
+#include <string>
+
+#include "board/board.hpp"
#include "misc.hpp"
#include "uci.hpp"
#include "zobrist.hpp"
-#include <iostream>
-int main() {
+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);
+ }
+
+ int depth = -1;
+ try {
+ depth = std::stoi(argv[2]);
+ } catch (const std::exception &) {
+ std::cout << "info string usage: ./mono perft <non-negative depth>\n";
+ exit(1);
+ }
+
+ if (depth < 0) {
+ 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 = MoveGenTest(depth, &game);
+
+ 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() << std::endl;
+}
+
+int main(int argc, char *argv[]) {
InitZobrist();
- std::cout << engine_info();
+ if (argc != 1) {
+ perft(argc, argv);
+ return 0;
+ }
+ std::cout << engine_info();
Uci();
return 0;
}
diff --git a/src/uci.cpp b/src/uci.cpp
index 0805c6c..1854019 100644
--- a/src/uci.cpp
+++ b/src/uci.cpp
@@ -286,31 +286,6 @@ void Uci() {
MakeMove(move, &game);
}
- } else if (cmd.starts_with("perft")) {
- std::istringstream iss(cmd);
-
- std::string word;
- int depth = -1;
-
- if (!(iss >> word >> depth) || word != "perft" || depth < 0) {
- cout << "info string usage: perft <non-negative depth>\n";
- cout.flush();
- continue;
- }
-
- auto start = std::chrono::steady_clock::now();
-
- uint64_t count = MoveGenTest(depth, &game);
-
- 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::string json = oss.str();
-
- std::cout << json << std::endl;
}
}
}