I'm trying to figure out how a traditional chess engine (no AI) works, and now I'm trying to collect pv (principal variation) moves using triangular table. So I'm using a NxN table and a very simple implementation
private Integer alphaBeta(final int depth, int alpha, int beta) {
...
pvLength[ply] = ply;
...
while (move != null) {
...
if (value > alpha) { // (1)
dPvTable[ply][ply] = move;
nextPly = ply + 1;
for (int p = nextPly; p < pvLength[nextPly]; ++p) {
pvTable[ply][p] = pvTable[nextPly][p];
}
pvLength[ply] = pvLength[nextPly];
...
}
...
}
...
}
I am comparing the extracted pv with the pv resulting from the transposition table.
It works well if the pv doesn't end with checkmate. If it does end with a checkmate, the triangular table returns only the first (correct) move.
I have tried many changes but without success. The only thing that works (at the expense of search speed) is to change the condition (1) to
if (value >= alpha) {
But clearly this is not an acceptable change, because this way the search explores the tree up to the last move, and does not end at the first checkmate found.
I just wanted to know, if anyone had the same problem: is this behavior due to a flaw in my implementation? Or this method just can't return all PV moves when there are checkmates?