From: Marco Costalba Date: Fri, 2 Nov 2012 23:30:46 +0000 (+0100) Subject: Fix an off-by-one bug in multi pv print X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=52f55179a8d0b24f5410cdd9d29559e4f6408156;hp=bbdf9e47376d5df2dd3e2a3498c04c9f27b88cec 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. --- 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; }