1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-02 01:29:36 +00:00

Rework perft implementation

Unify various perft functions and move all the code
to search.cpp.

Avoid perft implementation to be splitted between
benchmark.cpp (where it has no reason to be) and
search.cpp

No functional and no speed change (tested).
This commit is contained in:
Marco Costalba 2014-08-08 10:59:28 +02:00 committed by lucasart
parent 2efeded6e3
commit a67c22611a
3 changed files with 20 additions and 20 deletions

View file

@ -139,15 +139,8 @@ void benchmark(const Position& current, istream& is) {
cerr << "\nPosition: " << i + 1 << '/' << fens.size() << endl; cerr << "\nPosition: " << i + 1 << '/' << fens.size() << endl;
if (limitType == "perft") if (limitType == "perft")
for (MoveList<LEGAL> it(pos); *it; ++it) nodes += Search::perft<true>(pos, limits.depth * ONE_PLY);
{
StateInfo si;
pos.do_move(*it, si);
uint64_t cnt = limits.depth > 1 ? Search::perft(pos, (limits.depth - 1) * ONE_PLY) : 1;
pos.undo_move(*it);
cout << move_to_uci(*it, pos.is_chess960()) << ": " << cnt << endl;
nodes += cnt;
}
else else
{ {
Threads.start_thinking(pos, limits, st); Threads.start_thinking(pos, limits, st);

View file

@ -152,26 +152,33 @@ void Search::init() {
/// Search::perft() is our utility to verify move generation. All the leaf nodes /// 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. /// up to the given depth are generated and counted and the sum returned.
template<bool Root>
static uint64_t perft(Position& pos, Depth depth) { uint64_t Search::perft(Position& pos, Depth depth) {
StateInfo st; StateInfo st;
uint64_t cnt = 0; uint64_t cnt, nodes = 0;
CheckInfo ci(pos); CheckInfo ci(pos);
const bool leaf = depth == 2 * ONE_PLY; const bool leaf = depth == 2 * ONE_PLY;
for (MoveList<LEGAL> it(pos); *it; ++it) for (MoveList<LEGAL> it(pos); *it; ++it)
{
if (Root && depth <= ONE_PLY)
cnt = 1;
else
{ {
pos.do_move(*it, st, ci, pos.gives_check(*it, ci)); pos.do_move(*it, st, ci, pos.gives_check(*it, ci));
cnt += leaf ? MoveList<LEGAL>(pos).size() : ::perft(pos, depth - ONE_PLY); cnt = leaf ? MoveList<LEGAL>(pos).size() : perft<false>(pos, depth - ONE_PLY);
nodes += cnt;
pos.undo_move(*it); pos.undo_move(*it);
} }
return cnt; if (Root)
sync_cout << move_to_uci(*it, pos.is_chess960()) << ": " << cnt << sync_endl;
}
return nodes;
} }
uint64_t Search::perft(Position& pos, Depth depth) { template uint64_t Search::perft<true>(Position& pos, Depth depth);
return depth > ONE_PLY ? ::perft(pos, depth) : MoveList<LEGAL>(pos).size();
}
/// Search::think() is the external interface to Stockfish's search, and is /// 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 /// called by the main thread when the program receives the UCI 'go' command. It

View file

@ -105,8 +105,8 @@ extern Time::point SearchTime;
extern StateStackPtr SetupStates; extern StateStackPtr SetupStates;
extern void init(); extern void init();
extern uint64_t perft(Position& pos, Depth depth);
extern void think(); extern void think();
template<bool Root> uint64_t perft(Position& pos, Depth depth);
} // namespace Search } // namespace Search