Collecting PVs of Qsearch ?
Posted: Sat Oct 22, 2016 11:49 pm
what is the simplest way to collect the complete PV from the root to the evaluation ?
Code: Select all
MOVE pvLines[10000];
MOVE *pvPtr = pvLines;
Search()
{
MOVE *pvStart = pvPtr;
*pvPtr++ = 0; // invalid move code to indicate end of(now empty) PV
...
if(score > alpha) {
alpha = score;
if(score >= beta) break; // cutoff
// alpha < score < beta: new PV node
MOVE *p = pvPtr; // PV left by daughter
pvPtr = pvStart; // pop old PV
*pvPtr++ = move; // new best move of this node
while(*pvPtr++ = *p++) {} // copy PV of daughter behind it
}
...
pvPtr = pvStart; // cleanup
return alpha;
}
Or this way (maybe a bit more readable but slightly slower than the HGM code):MahmoudUthman wrote:what is the simplest way to collect the complete PV from the root to the evaluation ?
Code: Select all
struct PV {
Move move[63];
int size;
PV() : size(0) {}
void concat(Move const & m, PV const & pv)
{
move[0] = m;
int pvSize = min(pv.size, 63 - 1);
for (int i = 1; i <= pvSize; i++) {
move[i] = pv[i - 1];
}
size = pvSize + 1;
}
};
int search(..., PV & pv) // same for qSearch
{
...
for (all moves) {
PV localPV;
...
int v = -search(..., localPV);
...
if (v >= beta) CUTOFF;
if (v > alpha) {
pv.concat(move, localPV);
}
}
...
}