aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/misc.cpp16
-rw-r--r--src/misc.hpp4
-rw-r--r--src/uci.cpp18
3 files changed, 37 insertions, 1 deletions
diff --git a/src/misc.cpp b/src/misc.cpp
index 8527fdc..db9240c 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -1,4 +1,6 @@
#include "misc.hpp"
+#include "moves.hpp"
+#include <cstdint>
#include <string>
std::string version = "0";
@@ -6,3 +8,17 @@ std::string version = "0";
std::string engine_version() { return "Mono " + version; };
std::string engine_info() { return engine_version() + " by Adam " + "\n"; }
+
+uint64_t MoveGenTest(int depth, Game *g) {
+ uint64_t num = 0;
+ if (depth <= 0) {
+ return 1;
+ }
+ auto moves = GetLegalMoves(g);
+ for (auto move : moves) {
+ UndoMove undo = MakeMove(move, g);
+ num += MoveGenTest(depth - 1, g);
+ UnMakeMove(undo, g);
+ }
+ return num;
+}
diff --git a/src/misc.hpp b/src/misc.hpp
index 6bf8e02..c84edef 100644
--- a/src/misc.hpp
+++ b/src/misc.hpp
@@ -1,9 +1,13 @@
#ifndef SRC_MICS_H_
#define SRC_MICS_H_
+#include "board/board.hpp"
+#include <cstdint>
#include <string>
std::string engine_info();
std::string engine_version();
+uint64_t MoveGenTest(int depth, Game *g);
+
#endif /* SRC_MICS_H_ */
diff --git a/src/uci.cpp b/src/uci.cpp
index 89d28dd..8c24ed4 100644
--- a/src/uci.cpp
+++ b/src/uci.cpp
@@ -11,6 +11,7 @@
#include <cctype>
#include <cstdint>
#include <cstdio>
+#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
@@ -49,6 +50,7 @@ Move UciToMove(string uci) {
return {from, to};
}
+
Game initBoard(
string startingFEN,
std::unordered_map<uint64_t, TranspositionsEntry> *transPositions) {
@@ -115,7 +117,6 @@ void Uci() {
cout << "readyok\n";
cout.flush();
} else if (cmd.starts_with("go")) {
-
stringstream ss(line);
string token;
@@ -195,6 +196,21 @@ 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;
+ }
+ int count = MoveGenTest(depth, &game);
+
+ cout << count << "\n";
+ cout.flush();
}
}
}