mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-17 15:46:24 +08:00
Micro-optimize perft
Avoid to call perft function when we just need to count moves, at leaf nodes. Speed up of almost 2% No functional change.
This commit is contained in:
@@ -155,21 +155,17 @@ void Search::init() {
|
||||
|
||||
size_t Search::perft(Position& pos, Depth depth) {
|
||||
|
||||
// At the last ply just return the number of legal moves (leaf nodes)
|
||||
if (depth == ONE_PLY)
|
||||
return MoveList<LEGAL>(pos).size();
|
||||
|
||||
StateInfo st;
|
||||
size_t cnt = 0;
|
||||
CheckInfo ci(pos);
|
||||
const bool leaf = depth == 2 * ONE_PLY;
|
||||
|
||||
for (MoveList<LEGAL> it(pos); *it; ++it)
|
||||
{
|
||||
pos.do_move(*it, st, ci, pos.move_gives_check(*it, ci));
|
||||
cnt += perft(pos, depth - ONE_PLY);
|
||||
cnt += leaf ? MoveList<LEGAL>(pos).size() : perft(pos, depth - ONE_PLY);
|
||||
pos.undo_move(*it);
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user