From 63f380a48ab21f39962b60837fa487e9f978be95 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 31 Jul 2026 15:14:12 +0200 Subject: adding perft --- src/misc.cpp | 16 ++++++++++++++++ src/misc.hpp | 4 ++++ src/uci.cpp | 18 +++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) 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 #include 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 #include 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 #include #include +#include #include #include #include @@ -49,6 +50,7 @@ Move UciToMove(string uci) { return {from, to}; } + Game initBoard( string startingFEN, std::unordered_map *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 \n"; + cout.flush(); + continue; + } + int count = MoveGenTest(depth, &game); + + cout << count << "\n"; + cout.flush(); } } } -- cgit v1.2.3