From 9a66a71c38e2e690bbf5b428f981c7b0316c4f01 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Mon, 3 Feb 2025 13:59:33 +0100 Subject: [PATCH] handling better the output of perft --- cpp/src/stickfosh.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cpp/src/stickfosh.cpp b/cpp/src/stickfosh.cpp index 7798cef..e5efe09 100644 --- a/cpp/src/stickfosh.cpp +++ b/cpp/src/stickfosh.cpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include @@ -33,8 +35,14 @@ static std::map> pos2expected{ }, }; +static std::stringstream res; + int move_generation_test(Board& b, int depth, int max_depth) { - std::cout << "hello" << std::endl; + if (depth == max_depth) { + res.str(""); + res.clear(); + } + if (b.is_terminal()) return 0; if (depth == 0) @@ -47,7 +55,12 @@ int move_generation_test(Board& b, int depth, int max_depth) { int num_pos = 0; for (const Move& move : moves) { Board tmp_board = b.make_move(move); - num_pos += move_generation_test(tmp_board, depth - 1, max_depth); + int n = move_generation_test(tmp_board, depth - 1, max_depth); + if (depth == max_depth) + res << Coords::from_index(move.source_square) + << Coords::from_index(move.target_square) << ": " << n + << std::endl; + num_pos += n; } return num_pos; } @@ -57,7 +70,7 @@ void perft(std::string pos) { Board b = Board::setup_fen_position(pos); for (const auto& [depth, expected_n_moves] : expected) { - std::cout << "Depth: " << depth << " "; + std::cout << "Depth: " << depth << " " << std::flush; auto start = std::chrono::steady_clock::now(); int moves = move_generation_test(b, depth, depth); auto end = std::chrono::steady_clock::now(); @@ -72,5 +85,7 @@ void perft(std::string pos) { std::cout << cross << " (expected " << expected_n_moves << ") "; std::cout << "positions Time: " << elapsed << " milliseconds" << std::endl; + if (moves != expected_n_moves) + std::cout << res.str(); } }