Skip to content

Commit

Permalink
Fix an off-by-one bug in multi pv print
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mcostalba committed Nov 2, 2012
1 parent bbdf9e4 commit 52f5517
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/search.cpp
Expand Up @@ -394,7 +394,7 @@ namespace {
}

// Sort the PV lines searched so far and update the GUI
sort<RootMove>(RootMoves.begin(), RootMoves.begin() + PVIdx);
sort<RootMove>(RootMoves.begin(), RootMoves.begin() + PVIdx + 1);
sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl;
}

Expand Down
6 changes: 3 additions & 3 deletions src/types.h
Expand Up @@ -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<typename T, typename K>
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;
}
Expand Down

0 comments on commit 52f5517

Please sign in to comment.