/*1Stockfish, a UCI chess playing engine derived from Glaurung 2.12Copyright (C) 2004-2025 The Stockfish developers (see AUTHORS file)34Stockfish is free software: you can redistribute it and/or modify5it under the terms of the GNU General Public License as published by6the Free Software Foundation, either version 3 of the License, or7(at your option) any later version.89Stockfish is distributed in the hope that it will be useful,10but WITHOUT ANY WARRANTY; without even the implied warranty of11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12GNU General Public License for more details.1314You should have received a copy of the GNU General Public License15along with this program. If not, see <http://www.gnu.org/licenses/>.16*/1718#ifndef PERFT_H_INCLUDED19#define PERFT_H_INCLUDED2021#include <cstdint>2223#include "movegen.h"24#include "position.h"25#include "types.h"26#include "uci.h"2728namespace Stockfish::Benchmark {2930// Utility to verify move generation. All the leaf nodes up31// to the given depth are generated and counted, and the sum is returned.32template<bool Root>33uint64_t perft(Position& pos, Depth depth) {3435StateInfo st;3637uint64_t cnt, nodes = 0;38const bool leaf = (depth == 2);3940for (const auto& m : MoveList<LEGAL>(pos))41{42if (Root && depth <= 1)43cnt = 1, nodes++;44else45{46pos.do_move(m, st);47cnt = leaf ? MoveList<LEGAL>(pos).size() : perft<false>(pos, depth - 1);48nodes += cnt;49pos.undo_move(m);50}51if (Root)52sync_cout << UCIEngine::move(m, pos.is_chess960()) << ": " << cnt << sync_endl;53}54return nodes;55}5657inline uint64_t perft(const std::string& fen, Depth depth, bool isChess960) {58StateInfo st;59Position p;60p.set(fen, isChess960, &st);6162return perft<true>(p, depth);63}64}6566#endif // PERFT_H_INCLUDED676869