Trying to implement MTD(f) search algorithm in Prolog...



Hi there,

I'm trying to implement MTD(f) search algorithm in Prolog to improve a
Minimax search with Alpha-Beta pruning. The problem is that it seems to
return different values than the ones returned by Alpha-Beta by itself,
which I believe shouldn't happen (well, it shouldn't specially because the
returned result is not the best possible result with MTD(f) and it is with
Alpha-Beta...).
As far as I've realised (I'm not very experienced with Prolog actually)
MTD(f) requires an implementation of Alpha-Beta with memory, which I believe
I've already managed to write successfuly. Since I believe the problem is
with MTD(f) implementation and I can't find where the bug may be (I've based
this on Aske Plaat's pseudo-code at http://www.cs.vu.nl/~aske/mtdf.html that
you've probably all seen a million times). Maybe one of you could help sort
this out and point me in the right direction...
Here's what I have currently:

% condition to stop the loop at Aske Plaat's code
mtdf (_,_,Result,_,Lowerbound,Upperbound,Result) :-
Lowerbound >= Upperbound, !.

% the MTD(f) loop... I hope
mtdf(Board,Heuristic,(_,FirstGuess),Depth,Lowerbound,Upperbound,Result) :-
((FirstGuess == Lowerbound) ->
(Beta is FirstGuess + 1)
;
(Beta is FirstGuess)),
Alpha is Beta-1,
minimax_alphabeta(Depth,Board,Heuristic,Move,Score,(Alpha,Beta)),
((Score < Beta) ->
(Upper2 = Score,
Lower2 = Lowerbound)
;
(Lower2 = Score,
Upper2 = Upperbound)),
mtdf(Board,Heuristic,(Move,Score),Depth,Lower2,Upper2,Result.

Thanks in advance!


.