mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00: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:
parent
e95e69515a
commit
e215a88cdd
1 changed files with 2 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue