added bulk counting to perft + reorganized it's outputs

This commit is contained in:
rektdie committed 2024-04-03 08:31:42 +02:00
1 parent 5962c37546
commit 693cfd07ac
2 files changed
+16 -27

No files matched your search

-1
View File
@@ -29,7 +29,6 @@ public:
void PrintMove() {
std::cout << squareCoords[moveFrom] << squareCoords[moveTo];
std::cout << '(' << moveTypes[moveFlags] << ")\n";
}
};
+16 -26
View File
@@ -1,27 +1,15 @@
#include <chrono>
#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<milliseconds>(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";
}