prolog alpha-beta意外结果

问题描述

我将一本书的通用alpha-beta修改为受深度限制。当打印出最佳位置搜索结果时,它有时会起作用,有时我会得到讨厌的结果,例如数字8。

这是“人工智能的序言”中非常通用的alpha-beta。我正试图缩小问题的范围,以解决alpha-beta还是代码中的其他问题。

有人可以告诉我这个深度受限的alpha-beta是否可以吗?

代码如下:

alphabeta(Pos,Alpha,Beta,GoodPos,Val,Depth):-
   Depth > 0,moves(Pos,PosList),!,boundedbest(PosList,Depth);
   get_pos_value(Pos,Val).                              % static value of position

boundedbest([Pos | PosList],GoodVal,Depth):-
   NewDepth is Depth - 1,alphabeta(Pos,_,NewDepth),goodenough(PosList,Pos,Depth).

goodenough([],_):- !.                % no other candidate

goodenough(_,_) :-
   min_to_move(Pos),Val > Beta,!;                 % Maximizer attainded upper bound
   max_to_move(Pos),Val < Alpha,!.                 % Minimizer attained lower bound

goodenough(PosList,Depth):-
   newbounds(Alpha,NewAlpha,NewBeta),% refine bounds
   boundedbest(PosList,NewBeta,Pos1,Val1,Depth),betterof(Pos,GoodVal).

newbounds(Alpha,Beta):-
   min_to_move(Pos),Val > Alpha,!.                    % Maximizer increased lower bound

newbounds(Alpha,Val):-
   max_to_move(Pos),Val < Beta,!.                 % Minimizer decreased upper bound

newbounds(Alpha,Beta).             % otherwise bounds unchanged

betterof(Pos,Val):-               % Pos better than Pos1
   min_to_move(Pos),Val > Val1,!;
   max_to_move(Pos),Val < Val1,!.

betterof(_,Val1).                      % Otherwise Pos1 better

解决方法

以下是对这些谓词“好”和“好”的评论,它们以相同的方式编写。我想当Val> Val1或Beta时,您想要min_to_move,而在Val

goodenough(_,Alpha,Beta,Pos,Val,_) :-
   min_to_move(Pos),Val > Beta,!;                 % Maximizer attainded upper bound
   max_to_move(Pos),Val < Alpha,!.                 % Minimizer attained lower bound

betterof(Pos,Pos1,Val1,Val):-           % Pos better than Pos1
   min_to_move(Pos),Val > Val1,!;
   max_to_move(Pos),Val < Val1,!.

也许更明确地写成:

goodenough(_,_) :-
    Val > Beta,!,min_to_move(Pos).
goodenough(_,_) :-
    Val < Alpha,max_to_move(Pos).

此代码显示,在足够的情况下,您的析取不能处理某些情况, 解释为失败。这是故意的吗?

在goodenough / 8中,如果参数5 Val与参数7 Val不同,则谓词失败。这是故意的吗?

给我的印象是您在优化代码之前!