From 52f55179a8d0b24f5410cdd9d29559e4f6408156 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 3 Nov 2012 00:30:46 +0100 Subject: [PATCH] Fix an off-by-one bug in multi pv print We send to GUI multi-pv info after each cycle, not just once at the end of the PV loop. This is because at high depths a single root search can be very slow and we want to update the gui as soon as we have a new PV score. Idea is good but implementation is broken because sort() takes as arguments a pointer to the first element and one past the last element. So fix the bug and rename sort arguments to better reflect their meaning. Another hit by Hongzhi Cheng. Impressive! No functional change. --- src/search.cpp | 2 +- src/types.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 8dc1f85d..bfade6d0 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -394,7 +394,7 @@ namespace { } // Sort the PV lines searched so far and update the GUI - sort(RootMoves.begin(), RootMoves.begin() + PVIdx); + sort(RootMoves.begin(), RootMoves.begin() + PVIdx + 1); sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl; } diff --git a/src/types.h b/src/types.h index 1842eb2a..9b36fd89 100644 --- a/src/types.h +++ b/src/types.h @@ -490,15 +490,15 @@ inline const std::string square_to_string(Square s) { /// Our insertion sort implementation, works with pointers and iterators and is /// guaranteed to be stable, as is needed. template -void sort(K first, K last) +void sort(K begin, K end) { T tmp; K p, q; - for (p = first + 1; p < last; p++) + for (p = begin + 1; p < end; p++) { tmp = *p; - for (q = p; q != first && *(q-1) < tmp; --q) + for (q = p; q != begin && *(q-1) < tmp; --q) *q = *(q-1); *q = tmp; } -- 2.39.2