I am currently writing a chess engine and have progressed decently far, I have however run into a problem and would like a few opinions on the manner. Ok, my problem is the fact that my chess AI doesnt make the "best" move, It seems to fail to see simple things like the fact that its piece may be taken back or something. My alpha beta prunning goes as follows.
int Search (TREE *tree, int ply, int wtm, int alpha, int beta) {
if (0 == ply) {
return quiesce(tree, ply, wtm, alpha, beta);
}
movePointer = GenCaptures(tree, MAXPLY, wtm, moves);
movePointer = GenNonCaptures(tree, wtm, movePointer);
for (move = &moves[0]; move < movePointer; move++) {
MakeMove(tree, &tree->movePath[ply], wtm);
score = -Search(tree, ply - 1, Flip(wtm), -beta, -alpha);
UnmakeMove(tree, &tree->movePath[ply], wtm);
tree->movePath[ply].move = 0;
if (score >= beta) {
return beta;
}
if (score > alpha) {
alpha = score;
}
}
I think my alpha beta pruning works well enough because it does return reasonable moves, I think the problem is when I try to obtain my rootMove. Im trying to get the root move by (
int searchRoot( TREE *tree, int ply, int wtm ) {
//int depth = 1;
int moves[220];
int *movePointer = 0;
int *move = 0;
int rootAlpha = -MATE - 1;
int rootValue = -MATE - 1;
int rootBeta = MATE + 1;
MOVE currentMove;
currentMove.move = 0;
currentMove.capture = 0;
movePointer = GenCaptures( tree, MAXPLY, wtm, moves );
movePointer = GenNonCaptures( tree, wtm, movePointer );
for ( move = &moves[0]; move < movePointer; move++ ) {
currentMove.move = *move;
tree->movePath[MAXPLY] = currentMove;
MakeMove( tree, ¤tMove, wtm );
int lastValue = -Search( tree, MAXPLY -1, Flip(wtm), rootAlpha, rootBeta );
UnmakeMove( tree, ¤tMove, wtm );
if ( lastValue > rootValue ) {
tree->rootMove = *move; rootValue = lastValue;
}
}
}
Any ideas would be helpful, thank you.