In my chess program, I'm trying to implement for storing values of positions, which were already determined. I'm pretty frustrated with that, because maybe two weeks I can't find the mistake in my source code, but the program behaves strange: The moves are different when the transposition heuristic is used and when it is not used. The moves are not bad in both cases, but I think, that they should be the same, shouldn't they? My source code:
Code: Select all
int alfabeta(Board board, int depth, int alpha, int beta, int color) {
TranspositionItem transpoItem;
TranspositionTable transpoTable = board.transpositionTable;
if ((transpoItem = transpoTable.getContent()) != null ) {
if (transpoItem.getStep() >= depth ) {
if (transpoItem.getValueFlag() == TranspositionItem.EXACT_FLAG) {
return transpoItem.getValue();
}
if ((transpoItem.getValueFlag() == TranspositionItem.ALPHA_FLAG) &&(transpoItem.getValue() <= alpha)) {
return alpha;
}
if ((transpoItem.getValueFlag() == TranspositionItem.BETA_FLAG) &&(transpoItem.getValue() >= beta)) {
return beta;
}
}
}
MoveList moves = new MoveList();
moves.generate(board, color, false);
int value;
if ((timeExpired == true) || depth <= 0) {
MoveList opponentMoves = new MoveList();
opponentMoves.generate(board, -color, false);
return evaluation.value(board, moves, opponentMoves, color);
}
int flag = TranspositionItem.ALPHA_FLAG;
for (OneMove move: moves) {
board.playMove(move, false);
transpoTable.move(board, move);
if (!board.isCheck(color)) {
value = -alfabeta(board, depth - 1, -beta, -alpha, -color);
if (value > alpha) {
alpha=value;
flag = TranspositionItem.EXACT_FLAG;
if(value >= beta) {
transpoTable.move(board, move);
board.revertMove(move);
transpoTable.putRealPosition(beta, depth, TranspositionItem.BETA_FLAG);
return beta;
}
}
}
transpoTable.move(board, move);
board.revertMove(move);
}
transpoTable.putRealPosition(alpha, depth, flag);
return alpha;
}
Thanks a lot, Marika.