summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
e95e695)
Avoid to call perft function when we just need to count
moves, at leaf nodes.
Speed up of almost 2%
No functional change.
size_t Search::perft(Position& pos, Depth depth) {
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);
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));
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);