Minimax is implemented in Prolog Programming for Artificial Intelligence - what are min_to_move / 1 and max_to_move / 1?

Let me start by saying that AI wizards without Prolog experience can answer this question.

The excellent Prolog Programming for Artificial Intelligence book has this rather short and clever minimax implementation:

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

However, the author did not begin to describe this in detail, and I can only wonder what is min_to_move/1and max_to_move/1.

Can someone explain this to me?

Thanks in advance!

+5
source share
1 answer

-, min_to_move (Pos) , "" Pos. , max_to_move/1. , , , . , , -then-else ((- > )/2 (;)/2), , . (, , "position_best/2", , "/3" ) (, , " , , ," better_of "?).

+5

All Articles