X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=144776aac160bcc411bdc86a50592e98aa537abd;hp=3fb1345a892a9f7937135290fc60146a86ec8e33;hb=a903ed07e02780aec98f97461329acb78d7242c8;hpb=1b69910865a4add283ba32626acce4e03553a51c diff --git a/src/search.cpp b/src/search.cpp index 3fb1345a..144776aa 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -152,26 +152,33 @@ void Search::init() { /// Search::perft() is our utility to verify move generation. All the leaf nodes /// up to the given depth are generated and counted and the sum returned. - -static uint64_t perft(Position& pos, Depth depth) { +template +uint64_t Search::perft(Position& pos, Depth depth) { StateInfo st; - uint64_t cnt = 0; + uint64_t cnt, nodes = 0; CheckInfo ci(pos); const bool leaf = depth == 2 * ONE_PLY; for (MoveList it(pos); *it; ++it) { - pos.do_move(*it, st, ci, pos.gives_check(*it, ci)); - cnt += leaf ? MoveList(pos).size() : ::perft(pos, depth - ONE_PLY); - pos.undo_move(*it); + if (Root && depth <= ONE_PLY) + cnt = 1; + else + { + pos.do_move(*it, st, ci, pos.gives_check(*it, ci)); + cnt = leaf ? MoveList(pos).size() : perft(pos, depth - ONE_PLY); + nodes += cnt; + pos.undo_move(*it); + } + if (Root) + sync_cout << move_to_uci(*it, pos.is_chess960()) << ": " << cnt << sync_endl; } - return cnt; + return nodes; } -uint64_t Search::perft(Position& pos, Depth depth) { - return depth > ONE_PLY ? ::perft(pos, depth) : MoveList(pos).size(); -} +template uint64_t Search::perft(Position& pos, Depth depth); + /// Search::think() is the external interface to Stockfish's search, and is /// called by the main thread when the program receives the UCI 'go' command. It @@ -225,12 +232,9 @@ void Search::think() { Log log(Options["Search Log Filename"]); log << "Nodes: " << RootPos.nodes_searched() << "\nNodes/second: " << RootPos.nodes_searched() * 1000 / elapsed - << "\nBest move: " << move_to_san(RootPos, RootMoves[0].pv[0]); - - StateInfo st; - RootPos.do_move(RootMoves[0].pv[0], st); - log << "\nPonder move: " << move_to_san(RootPos, RootMoves[0].pv[1]) << std::endl; - RootPos.undo_move(RootMoves[0].pv[0]); + << "\nBest move: " << move_to_uci(RootMoves[0].pv[0], RootPos.is_chess960()) + << "\nPonder move: " << move_to_uci(RootMoves[0].pv[1], RootPos.is_chess960()) + << std::endl; } finalize: