【问题标题】:Minimax implement in "Prolog Programming for Artificial Intelligence" - what are min_to_move/1 and max_to_move/1?“Prolog 人工智能编程”中的 Minimax 实现 - 什么是 min_to_move/1 和 max_to_move/1?
【发布时间】:2011-11-02 11:22:48
【问题描述】:

首先让我说这个问题可能由没有 Prolog 经验的 AI 向导来回答。

优秀的Prolog Programming for Artificial Intelligence 书有这个非常简洁和巧妙的极小极大实现:

minimax( Pos, BestSucc, Val)  :-
  moves( Pos, PosList), !,               % Legal moves in Pos produce PosList
  best( PosList, BestSucc, Val)
   ;
   staticval( Pos, Val).                 % Pos has no successors: evaluate statically 

best( [ Pos], Pos, Val)  :-
  minimax( Pos, _, Val), !.

best( [Pos1 | PosList], BestPos, BestVal)  :-
  minimax( Pos1, _, Val1),
  best( PosList, Pos2, Val2),
  betterof( Pos1, Val1, Pos2, Val2, BestPos, BestVal).

betterof( Pos0, Val0, Pos1, Val1, Pos0, Val0)  :-        % Pos0 better than Pos1
  min_to_move( Pos0),                                    % MIN to move in Pos0
  Val0 > Val1, !                                         % MAX prefers the greater value
  ;
  max_to_move( Pos0),                                    % MAX to move in Pos0
  Val0 < Val1, !.                                % MIN prefers the lesser value 

betterof( Pos0, Val0, Pos1, Val1, Pos1, Val1).           % Otherwise Pos1 better than Pos0

但是,作者并没有详细描述它,我想知道min_to_move/1max_to_move/1 是什么。

谁能给我解释一下?

提前致谢!

【问题讨论】:

    标签: prolog artificial-intelligence minimax


    【解决方案1】:

    显然,当且仅当“最小化”玩家要在 Pos 位置移动时,min_to_move(Pos) 才为真。 max_to_move/1 则相反。就个人而言,我发现这里描述的编码风格不是很好。例如,在某些情况下,if-then-else ((->)/2 和 (;)/2) 似乎更适合表达意图。谓词名称也可以更具描述性(例如考虑“positions_best/2”来描述位置列表和最佳选择之间的关系,而不仅仅是“best/3”)并且更具可读性(例如“ betterof”,除了比“better_of”更难阅读?)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多