From 693cfd07ac2c1c4357d8ff1450dde4b26e98a14d Mon Sep 17 00:00:00 2001 From: rektdie Date: Wed, 3 Apr 2024 08:31:42 +0200 Subject: [PATCH] added bulk counting to perft + reorganized it's outputs --- source/move.h | 1 - source/perft.cpp | 42 ++++++++++++++++-------------------------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/source/move.h b/source/move.h index 53ec6ac..4e824ea 100644 --- a/source/move.h +++ b/source/move.h @@ -29,7 +29,6 @@ public: void PrintMove() { std::cout << squareCoords[moveFrom] << squareCoords[moveTo]; - std::cout << '(' << moveTypes[moveFlags] << ")\n"; } }; diff --git a/source/perft.cpp b/source/perft.cpp index 04dd4c4..2abc68e 100644 --- a/source/perft.cpp +++ b/source/perft.cpp @@ -1,27 +1,15 @@ #include #include "perft.h" -static int captures = 0; -static int epCaptures = 0; -static int castles = 0; -static int promotions = 0; -static int checks = 0; - - U64 HelperPerft(Board board, int depth) { - if (depth == 0) return 1ULL; - GenerateMoves(board, board.sideToMove); + if (depth == 1) return board.moveList.size(); + U64 nodes = 0; for (int i = 0; i < board.moveList.size(); i++) { - if (board.moveList[i].moveFlags == capture) captures++; - if (board.moveList[i].moveFlags == epCapture) epCaptures++; - if (board.moveList[i].moveFlags == kingCastle || board.moveList[i].moveFlags == queenCastle) castles++; - if (board.moveList[i].moveFlags >= knightPromotion) promotions++; board.MakeMove(board.moveList[i]); - if (board.InCheck(board.sideToMove)) checks++; nodes += HelperPerft(board, depth - 1); board.UnmakeMove(); } @@ -33,11 +21,18 @@ void Perft(Board &board, int depth) { using std::chrono::milliseconds; using std::chrono::duration_cast; - captures = 0; - epCaptures = 0; - castles = 0; - promotions = 0; - checks = 0; + GenerateMoves(board, board.sideToMove); + + int totalNodes = 0; + + for (int i = 0; i < board.moveList.size(); i++) { + board.MakeMove(board.moveList[i]); + int nodeCount = HelperPerft(board, depth - 1); + totalNodes += nodeCount; + board.moveList[i].PrintMove(); + board.UnmakeMove(); + std::cout << ": " << nodeCount << '\n'; + } auto start = high_resolution_clock::now(); U64 nodes = HelperPerft(board, depth); @@ -45,13 +40,8 @@ void Perft(Board &board, int depth) { auto duration = duration_cast(end - start); - std::cout << "Depth: " << depth << '\n'; - std::cout << "Nodes searched: " << nodes << '\n'; - std::cout << "Captures: " << captures << '\n'; - std::cout << "epCaptures: " << epCaptures << '\n'; - std::cout << "Castles: " << castles << '\n'; - std::cout << "Promotions: " << promotions << '\n'; - std::cout << "Checks: " << checks << '\n' << '\n'; + std::cout << "\nDepth: " << depth << '\n'; + std::cout << "Total nodes: " << totalNodes << '\n'; std::cout << "Total time taken: " << duration.count() << " ms"; std::cout << " (" << (nodes / duration.count()) * 1000 << " nodes/sec)\n"; } \ No newline at end of file