Minimax implement in “Prolog Programming for Artificial Intelligence” - what are min_to_move/1 and max_to_move/1?

StackOverflow https://stackoverflow.com/questions/7979517

Question

Let me start by saying that this question can possibly be answered by AI wizards with no Prolog experience.

The excellent Prolog Programming for Artificial Intelligence book has this quite terse 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 didn't go to much length in describing it and I'm left to wonder what min_to_move/1 and max_to_move/1 are.

Can anyone explain these to me?

Thanks in advance!

Was it helpful?

Solution

Apparently, min_to_move(Pos) is true if and only if the "minimizing" player is to make a move in position Pos. Conversely for max_to_move/1. Personally, I find the coding style depticted here not very good. For example, on several occasions, if-then-else ((->)/2 and (;)/2) seems to be a better fit to express the intention. The predicate names could also be much more descriptive (consider for example "positions_best/2" to describe a relation between a list of positions and a best choice, instead of just "best/3") and more readable (what is for example "betterof" in addition to just being harder to read than for example "better_of"?).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top