|
@@ -2,6 +2,8 @@
|
|
#include "ChessGame.h"
|
|
#include "ChessGame.h"
|
|
#include "Search.h"
|
|
#include "Search.h"
|
|
|
|
|
|
|
|
+#include <iostream>
|
|
|
|
+
|
|
#include <functional>
|
|
#include <functional>
|
|
#include <limits>
|
|
#include <limits>
|
|
|
|
|
|
@@ -11,24 +13,31 @@ using namespace chessy;
|
|
size_t Perft::search(void)
|
|
size_t Perft::search(void)
|
|
{
|
|
{
|
|
size_t result = 0;
|
|
size_t result = 0;
|
|
- auto searcher = [&result] (const MoveInfo& mi, ChessGame& cg, int depth) {
|
|
|
|
|
|
+ std::function<void(const MoveInfo&, ChessGame&, int, bool)> searcher;
|
|
|
|
+ searcher = [&result, &searcher] (const MoveInfo& mi, ChessGame& cg, int depth, bool print) {
|
|
if (depth > 1) {
|
|
if (depth > 1) {
|
|
UndoInfo ui = cg.doMove(mi);
|
|
UndoInfo ui = cg.doMove(mi);
|
|
- Perft p{ depth - 1, cg };
|
|
|
|
- result += p.search();
|
|
|
|
|
|
+ Search<decltype(searcher)&> search (searcher, cg);
|
|
|
|
+ size_t interRes = result;
|
|
|
|
+ if (cg.getTurn() == WHITE_SIDE)
|
|
|
|
+ search.iterateAll<WHITE_SIDE>(cg, depth - 1, false);
|
|
|
|
+ else
|
|
|
|
+ search.iterateAll<BLACK_SIDE>(cg, depth - 1, false);
|
|
|
|
+ if (print)
|
|
|
|
+ std::cout << mi.move.asString() << ": " << (result - interRes) << std::endl;
|
|
|
|
+
|
|
cg.undoMove(ui);
|
|
cg.undoMove(ui);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
result++;
|
|
result++;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
-
|
|
|
|
- Search<decltype(searcher)> search (searcher, chessGame);
|
|
|
|
-
|
|
|
|
|
|
+ Search<decltype(searcher)&> search (searcher, chessGame);
|
|
if (chessGame.getTurn() == WHITE_SIDE)
|
|
if (chessGame.getTurn() == WHITE_SIDE)
|
|
- search.iterateAll<WHITE_SIDE>(chessGame, depth);
|
|
|
|
|
|
+ search.iterateAll<WHITE_SIDE>(chessGame, depth, true);
|
|
else
|
|
else
|
|
- search.iterateAll<BLACK_SIDE>(chessGame, depth);
|
|
|
|
|
|
+ search.iterateAll<BLACK_SIDE>(chessGame, depth, true);
|
|
|
|
+
|
|
|
|
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|