My chess engine, Vicki, currently plays without a transposition table. As this is rather embarrassing, I've started to implement one. However, Vicki plays substantially weaker with it and I have no idea why. Either there is a bug in the TT or it could be because of timing issues. Vicki often has to "hard stop" when it tries to search one ply deeper after the previous iteration returns immediately. Here is the main search algorithm that I used in shortened form:
- Code: Select all
alphabeta(n, alpha, beta)
{
if (position is drawn) return DRAWN
if (time up)
{
quitsearch = 1
return ZERO
}
value = probeTranspositionTable(n, alpha, beta, move)
if (value != UNKNOWN) return value
if (n <= 0)
{
value = quiescentSearch(alpha, beta)
dumpTranspostionTable(value, 0, EXAXT, NO_MOVE)
}
genAllMoves()
possibleMate = 1
bestmove = 0
hashtype = ALPHA
for each move, mv
{
makeMove(mv)
if (illegalMove) // leaves king in check, castling not allowed, etc.
{
takeBack(mv)
continue
}
possibleMate = 0
value = alphabeta(n-1, -beta, -alpha)
if (quitSearch) return ZERO
if (value>=beta)
{
dumpTranspostionTable(value, 0, BETA, mv)
return beta
}
if (value>alpha)
{
bestmove = mv
alpha = value
hashtype = EXAXT
}
}
if (possibleMate)
{
if (kingInCheck) // checkmate
{
dumpTranspostionTable(-MATE, 0, EXACT, NO_MOVE)
return -MATE
} else { // stalemate
dumpTranspostionTable(DRAWN, 0, EXACT, NO_MOVE)
return DRAW
}
}
dumpTranspostionTable(alpha, n, hashtype, bestmove)
}
probeTranspositionTable(n, alpha, beta, move)
{
HASHENTRY *he = ce_tt[zobrist%TT_SIZE]
if (he->zob = zobrist)
{
if (he->flags==EXACT) return he->value;
if ((he->flags==ALPHA) && (he->value<=alpha)) return alpha;
if ((he->flags==BETA) && (he->value>=beta)) return beta;
}
return UNKNOWN
}
dumpTranspostionTable(value, 0, type, best_move_in_position)
{
HASHENTRY *he = ce_tt[zobrist%TT_SIZE]
store at position based on depth and age
}
As you know so much depend on the transposition table. I desperately want to get this working, so I get rewrite the move ordering routine to give a higher score for the move returned by the TT for a given position. Also, extracting the PV from the TT is also much more elegant.
I would greatly appreciate any help/hints/comments from the forum.
Thank you!!