序言中深度限制的alpha-beta

问题描述

我正在Prolog中构建象棋引擎。 “用于人工智能的序言”的alpha-beta不受深度限制。 由于无法在国际象棋中搜索整棵树,因此我尝试将书中的代码修改为深度受限,但无法正常工作。

这是本书的代码:

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

boundedbest([Pos | PosList],GoodVal) :-
   alphabeta( Pos,_,Val),goodenough(PosList,Pos,Val,GoodVal).

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

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

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

newbounds(Alpha,Beta) :-
   min_to_move(Pos),Val > Alpha,!.                    % Mazximizer 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 Pos 1 better

我尝试将其修改为深度受限:

alphabeta(Pos,0) :- % max depth of search recieved
   get_pos_value(Pos,Val).                      % static value of Pos


alphabeta(Pos,Depth) :-
   Depth > 0,moves(Pos,Depth).


alphabeta(Pos,get_pos_value(Pos,Val).


boundedbest([Pos | PosList],GoodVal,Depth) :-
   Depth is Depth - 1,alphabeta( Pos,Depth1),_),!.                % Mazximizer increased lower bound

newbounds(Alpha,Val1).                          % otherwise Pos 1 better

我将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)