added perft back + fixed some bugs with movegen
This commit is contained in:
1 parent
7e541a40ed
commit
494cd13f7e
5 files changed
+61
-53
No files matched your search
+37
-36
@@ -1,45 +1,46 @@
|
||||
// #include <chrono>
|
||||
// #include "perft.h"
|
||||
#include <chrono>
|
||||
#include "perft.h"
|
||||
|
||||
// U64 HelperPerft(Board board, int depth) {
|
||||
// GenerateMoves(board, board.sideToMove);
|
||||
U64 HelperPerft(Board board, int depth) {
|
||||
GenerateMoves(board, board.sideToMove);
|
||||
|
||||
// if (depth == 1) return board.moveList.size();
|
||||
// if (depth == 0) return 1ULL;
|
||||
if (depth == 1) return board.moveList.size();
|
||||
if (depth == 0) return 1ULL;
|
||||
|
||||
// U64 nodes = 0;
|
||||
U64 nodes = 0;
|
||||
|
||||
// for (int i = 0; i < board.moveList.size(); i++) {
|
||||
// board.MakeMove(board.moveList[i]);
|
||||
// nodes += HelperPerft(board, depth - 1);
|
||||
// board.UnmakeMove();
|
||||
// }
|
||||
// return nodes;
|
||||
// }
|
||||
for (int i = 0; i < board.moveList.size(); i++) {
|
||||
Board copy = board;
|
||||
board.MakeMove(board.moveList[i]);
|
||||
nodes += HelperPerft(board, depth - 1);
|
||||
board = copy;
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
// void Perft(Board &board, int depth) {
|
||||
// GenerateMoves(board, board.sideToMove);
|
||||
void Perft(Board &board, int depth) {
|
||||
GenerateMoves(board, board.sideToMove);
|
||||
|
||||
// U64 totalNodes = 0;
|
||||
U64 totalNodes = 0;
|
||||
|
||||
// for (int i = 0; i < board.moveList.size(); i++) {
|
||||
// board.MakeMove(board.moveList[i]);
|
||||
// U64 nodeCount = HelperPerft(board, depth - 1);
|
||||
// totalNodes += nodeCount;
|
||||
// board.moveList[i].PrintMove();
|
||||
// board.UnmakeMove();
|
||||
// std::cout << ": " << nodeCount << '\n';
|
||||
// }
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
for (int i = 0; i < board.moveList.size(); i++) {
|
||||
Board copy = board;
|
||||
board.MakeMove(board.moveList[i]);
|
||||
U64 nodeCount = HelperPerft(board, depth - 1);
|
||||
board = copy;
|
||||
totalNodes += nodeCount;
|
||||
std::cout << squareCoords[board.moveList[i].MoveFrom()]
|
||||
<< squareCoords[board.moveList[i].MoveTo()];
|
||||
std::cout << ": " << nodeCount << '\n';
|
||||
}
|
||||
auto finish = std::chrono::steady_clock::now();
|
||||
|
||||
// auto start = std::chrono::steady_clock::now();
|
||||
// U64 nodes = HelperPerft(board, depth);
|
||||
// auto finish = std::chrono::steady_clock::now();
|
||||
double elapsed_seconds = std::chrono::duration_cast<
|
||||
std::chrono::duration<double>>(finish - start).count();
|
||||
|
||||
// double elapsed_seconds = std::chrono::duration_cast<
|
||||
// std::chrono::duration<double>>(finish - start).count();
|
||||
|
||||
// std::cout << "\nDepth: " << depth << '\n';
|
||||
// std::cout << "Total nodes: " << totalNodes << '\n';
|
||||
// std::cout << "Time took: " << elapsed_seconds << "s (";
|
||||
// std::cout << nodes / elapsed_seconds << " nodes/sec)\n";
|
||||
// }
|
||||
std::cout << "\nDepth: " << depth << '\n';
|
||||
std::cout << "Total nodes: " << totalNodes << '\n';
|
||||
std::cout << "Time took: " << elapsed_seconds << "s (";
|
||||
std::cout << int(totalNodes / elapsed_seconds * 1000) << " nodes/sec)\n";
|
||||
}
|
||||
Reference in new issue
Block a user