heavy sigh. OK, I am experimenting with different hashing schemes, and something isn't right.
Right now I have set up two arrays. A one dimensional array of 64-bit integers, hkey[], that contains the key, and a two dimensional array of 32 bit integers hVal[][], that contains ply (or depth if you prefer) and eval.
ok in between the doMove() and undoMove() in alphaBeta I have the foillowing code...
Code: Select all
if( zKey == hKey[hIndex] ) {
if( ply == hVal[0][hIndex] ) eval = hVal[1][hIndex];
else {
eval = -alphaBeta( ply+1, -beta, -alpha );
hVal[0][hIndex] = ply;
hVal[1][hIndex] = eval;
}
}
else {
eval = -alphaBeta( ply+1, -beta, -alpha );
hKey[hIndex] = zKey;
hVal[0][hIndex] = ply;
hVal[1][hIndex] = eval;
}
to me this says if the keys match, then check if the ply matches. If the ply matches then take the stored eval. If the keys match but the ply does not, do a search and replace the stored ply and eval, keeping the stored key. If the key does not match, do a search and replace, for that index, the key, the ply, and the eval.
But this scheme gives incorrect results. However, if the above code is restricted to a certain ply, it works, for example the following gives correct results...
Code: Select all
if( ply == 3 ) {
if( zKey == hKey[hIndex] ) {
if( ply == hVal[0][hIndex] ) eval = hVal[1][hIndex];
else {
eval = -alphaBeta( ply+1, -beta, -alpha );
hVal[0][hIndex] = ply;
hVal[1][hIndex] = eval;
}
}
else {
eval = -alphaBeta( ply+1, -beta, -alpha );
hKey[hIndex] = zKey;
hVal[0][hIndex] = ply;
hVal[1][hIndex] = eval;
}
}
else eval = -alphaBeta( ply+1, -beta, -alpha );
Putting aside whether or not these are good strategies, and assuming for the moment that my calculations of the zKey and index is correct, is there something wrong with the first block that I can't see? It looks ok to me, and if it is then I suppose there is nothing else but the calculation of the key to examine. Am I clear on this question?