Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

pl:prolog:pllib:minimax_principle [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Minimax principle ======
 +{{tag>​problem_solving}}
 +===== Description =====
 +A straightforward implementation of the minimax principle.
 +
 +**Source**: ​ PROLOG programming for artificial intelligence,​ 3rd Edition, Harlow, 2001, ISBN 0-201-40375-7.
 +===== Download =====
 +Program source code: {{minimax_principle.pl}}
 +===== Listing =====
 +<code prolog>
 +% Figure 22.3  A straightforward implementation of the minimax principle.
 +
 +
 +% minimax( Pos, BestSucc, Val):
 +%    Pos is a position, Val is its minimax value;
 +%    best move from Pos leads to position BestSucc
 +
 +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
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/minimax_principle.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0