I'm pretty new to chess programming has a hobby. I've done a lot of contest programming and I work in software development.
I feel like I'm implementing my tranposition table wrong because I'm not getting as much of a search depth improvement with it as I expected. I've checked the hashing thoroughly. Could someone look over my code for me?
I know it's not easy going over 50+ lines of code written by someone else, but I do appreciate any help!
I use an array of size 2 million to store my entries. I replace only if the new entry has higher depth, or has the same depth and a better bound. In case of a collision, I replace if the new entry has a higher depth.
Each entry contains the following information about a single state. It includes a lower bound and upper bound on the score of the node. These bounds may have been from different depths.
- wholeHash : the entire 64bit hash value of the node.
- bestMoveInd : index of the best move we've seen at minDepth
- minDepth : the depth of the lower bound.
- minScore : lower bound of the score
- maxDepth : the depth of the upper bound.
- maxScore : upper bound of the score
Code: Select all
void AI::tryAddTranspose(NodeType type, int depth, int ind, int score){
TranspositionData curData = TT[game.getHash()%TTSize];
//we have a collision
if (game.getHash() != curData.wholeHash){
//Override IFF this entry has higher depth
if (depth > max(curData.maxDepth,curData.minDepth) ){
curData = TranspositionData();
} else {
return;
}
}
//In case of a new entry or an override..
curData.wholeHash = game.getHash();
if (type == PV || type == ALL){
if (depth > curData.maxDepth){
curData.maxDepth = depth;
curData.maxScore = score;
} else if (depth == curData.maxDepth){
curData.maxScore = min(curData.maxScore,score);
}
}
if (type == PV || type == CUT){
if (depth > curData.minDepth ){
curData.minDepth = depth;
curData.minScore = score;
curData.bestMoveInd = ind;
} else if (depth == curData.minDepth && score>curData.minScore){
curData.minScore = score;
curData.bestMoveInd = ind;
}
}
TT[game.getHash()%TTSize] = curData;
}
TranspositionQueryResult AI::queryTT(int depth) const{
TranspositionData curData = TT[game.getHash()%TTSize];
//We have a collision
if (curData.wholeHash != game.getHash()){
return TranspositionQueryResult(-INF,INF,NO_MOVE);
}
int minToReturn = (depth <= curData.minDepth) ? curData.minScore : -INF;
int maxToReturn = (depth <= curData.maxDepth) ? curData.maxScore : INF;
return TranspositionQueryResult(minToReturn,maxToReturn,curData.bestMoveInd);
}