From 3b2bcee0a865e18fcc38a4d0aa648053960432a8 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 4 Jun 2011 11:29:54 +0100 Subject: [PATCH] Skip draw by repetition check in qsearch Cut in half the time spent in pos.draw() that accounts for a whopping 1% of total time ! Signed-off-by: Marco Costalba --- src/position.cpp | 13 +++++++++---- src/position.h | 2 +- src/search.cpp | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index 867a7f0b..4613ec4d 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1778,7 +1778,7 @@ Value Position::compute_non_pawn_material(Color c) const { /// Position::is_draw() tests whether the position is drawn by material, /// repetition, or the 50 moves rule. It does not detect stalemates, this /// must be done by the search. - +template bool Position::is_draw() const { // Draw by material? @@ -1791,13 +1791,18 @@ bool Position::is_draw() const { return true; // Draw by repetition? - for (int i = 4, e = Min(Min(st->gamePly, st->rule50), st->pliesFromNull); i <= e; i += 2) - if (history[st->gamePly - i] == st->key) - return true; + if (!SkipRepetition) + for (int i = 4, e = Min(Min(st->gamePly, st->rule50), st->pliesFromNull); i <= e; i += 2) + if (history[st->gamePly - i] == st->key) + return true; return false; } +// Explicit template instantiations +template bool Position::is_draw() const; +template bool Position::is_draw() const; + /// Position::is_mate() returns true or false depending on whether the /// side to move is checkmated. diff --git a/src/position.h b/src/position.h index 49f89e6c..6c48b54c 100644 --- a/src/position.h +++ b/src/position.h @@ -228,7 +228,7 @@ public: // Game termination checks bool is_mate() const; - bool is_draw() const; + template bool is_draw() const; // Number of plies from starting position int startpos_ply_counter() const; diff --git a/src/search.cpp b/src/search.cpp index b9fdcea1..ec2b1c9c 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -763,7 +763,7 @@ namespace { // Step 2. Check for aborted search and immediate draw if (( StopRequest - || pos.is_draw() + || pos.is_draw() || ss->ply > PLY_MAX) && !RootNode) return VALUE_DRAW; @@ -1333,7 +1333,7 @@ split_point_start: // At split points actual search starts from here ss->ply = (ss-1)->ply + 1; // Check for an instant draw or maximum ply reached - if (ss->ply > PLY_MAX || pos.is_draw()) + if (pos.is_draw() || ss->ply > PLY_MAX) return VALUE_DRAW; // Decide whether or not to include checks, this fixes also the type of @@ -2019,7 +2019,7 @@ split_point_start: // At split points actual search starts from here && pos.move_is_pl(tte->move()) && pos.pl_move_is_legal(tte->move(), pos.pinned_pieces(pos.side_to_move())) && ply < PLY_MAX - && (!pos.is_draw() || ply < 2)) + && (!pos.is_draw() || ply < 2)) { pv[ply] = tte->move(); pos.do_move(pv[ply++], *st++); -- 2.39.2