need help for alphabeta prunings best move
hello everybody,
can somebody tell me how to record the best move found by alpha-beta ???? My problem is that the initial board-position leads to mate in 2 for white winning the game, but there are moves in the game-tree that lead to mate too(!!). I need the move that leads to the shortest check-mate-path but how do i implement this???
my algorithm (in pseudo-code):
------------------------------
int alpha_beta(ushort depth,
int alpha,
int beta,
Board bb,
Move *ptr_best_move,
ushort tree_level)
{
all_moves = bb.GenLegalMoves();
// detect check-mate and return -INFINITY ...
if((all_moves.size() == 0) && (bb.InCheck()))
return (MININT32);
// leaf reached, eval board here ...
if(depth == 0)
return (eval_board_pos(bb));
int score = MININT32;
for(uint i=0; i<all_moves.size(); i++)
{
Board temp_board(bb);
Move act_move = all_moves;
temp_board.MakeMove(&act_move, temp_board);
int cur = -(alpha_beta( depth-1, -beta, -alpha, temp_board, ptr_best_move, tree_level+1));
temp_board = bb;
if(cur > score) score = cur;
if(score > alpha)
{
alpha = score;
*ptr_best_move = act_move;
}
if(alpha >= beta)
return alpha;
}
return score;
}
the problem is that mate is found on a longer path and that no following move can top the score of the first found mate... i need the move thats leading to the shortest mate-path.
i looked through the forum for similar topics but could not find any code or article that could help me..
thank you verry much for any kind of help or hint by now.
greetings.
Instead of returning -Infinity in case of being mated, return -Infinity+distance_to_root, so your program will prefer shorter mates if it's winning and longer mates if it's losing.
Dealing with these scores in the transposition tables is tricky, but if you don't have transposition tables this should work without much trouble.
You need to detect stalemate as well. When there are no moves available, you need to return 0 if we are not in check.
Dealing with these scores in the transposition tables is tricky, but if you don't have transposition tables this should work without much trouble.
You need to detect stalemate as well. When there are no moves available, you need to return 0 if we are not in check.
thnx verrrry much alvaro !!!
now it works, have tried several mate problems ... (sometimes the easiest solutions are the hardest to find) ... dont know why this simple solution did not came to my mind :)
could you please tell me what the general way to solve the problem of my previous post is since you have written that this way will be tricky if i use transpostion tables?
(i guess in that case i have to keep track of the shortest path in some other way, but how?)
one last question: does anybody know a GOOD book (available at amazon) explaining chess-programming in general (plus details like the ones in my post??)
thnx verry much by now.
greetings.
now it works, have tried several mate problems ... (sometimes the easiest solutions are the hardest to find) ... dont know why this simple solution did not came to my mind :)
could you please tell me what the general way to solve the problem of my previous post is since you have written that this way will be tricky if i use transpostion tables?
(i guess in that case i have to keep track of the shortest path in some other way, but how?)
one last question: does anybody know a GOOD book (available at amazon) explaining chess-programming in general (plus details like the ones in my post??)
thnx verry much by now.
greetings.
Transposition tables are going to get in the way of finding the shortest mate no matter how you do it. Of all the things I have tried, what works best is what Bruce Moreland proposes in this website.
By the way, http://www.brucemo.com/compchess/programming/ is better than any books I know of. I have a few computer chess books, but none of them are very good.
By the way, http://www.brucemo.com/compchess/programming/ is better than any books I know of. I have a few computer chess books, but none of them are very good.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement