Game Playing Using MiniMax with Alpha-Beta Cutoff

Perfect Information Games

Evaluation function

MiniMax

Imperfect Information Game

MINIMAX Game Strategy

Function MINIMAX

	function MINIMAX(N) is
	begin
	   if N is a leaf then
	        return the estimated score of this leaf
	   else
	        Let N1, N2, .., Nm be the successors of N;
	        if N is a Min node then
		    return min{MINIMAX(N1), .., MINIMAX(Nm)}
	        else
		    return max{MINIMAX(N1), .., MINIMAX(Nm)}
	end MINIMAX;

ALPHA-BETA Pruning

ALPHA-BETA cutoff is a method for reducing the number of nodes explored in the Minimax strategy. For the nodes it explores it computes, in addition to the score, an alpha value and a beta value.

ALPHA value of a node

BETA value of a node

It Is Guaranteed That:

Function MINIMAX-AB

	function MINIMAX-AB(N, A, B) is ;; Here A is always less than B
	begin
	   if N is a leaf then
	        return the estimated score of this leaf
	   else
		Set Alpha value of N to -infinity and 
                    Beta value of N to +infinity;
	        if N is a Min node then
	            For each successor Ni of N loop
		       Let Val be MINIMAX-AB(Ni, A, Min{B,Beta of N});
		       Set Beta value of N to Min{Beta value of N, Val};
		       When A >= Beta value of N then 
			   Return Beta value of N endloop;
                    Return Beta value of N;
	        else
	            For each successor Ni of N loop
		       Let Val be MINIMAX-AB(Ni, Max{A,Alpha value of N}, B);
		       Set Alpha value of N to Max{Alpha value of N, Val};
		       When Alpha value of N >= B then 
			  Return Alpha value of N endloop;
		    Return Alpha value of N;
	end MINIMAX-AB;

Starting the Game

An Example of MiniMax with Alpha Beta Cutoff

In the game tree that you see, the root is a Max node. The scores of the leaf nodes are presented immediately below them.

Trace of the Execution

Here is a trace of the execution of the Minimax strategy with Alpha Beta Cutoff

	NODE	TYPE	 A	B	ALPHA	BETA	SCORE

	A	Max	-I	+I	-I	+I
	B	Min	-I	+I	-I	+I
	C	Max	-I	+I	-I	+I
	D	Min	-I	+I	-I	+I
	E	Max	-I	+I			10
	D	Min	-I	+I	-I	10
	F	Max	-I	10			11
	D	Min	-I	+I	-I	10	10
	C	Max	-I	+I	10	+I
	G	Min	10	+I	-I	+I
	H	Max	10	+I			9
	G	Min	10	+I	-I	9	9
	C	Max	-I	+I	10	+I	10
	B	Min	-I	+I	-I	10
	J	Max	-I	10	-I	+I
	K	Min	-I	10	-I	+I
	L	Max	-I	10			14
	K	Min	-I	10	-I	14
	M	Max	-I	10			15
	K	Min	-I	10	-I	14	14
	J	Max	-I	10	14	+I	14
	B	Min	-I	+I	-I	10	10
	A	Max	-I	+I	10	+I
	Q	Min	10	+I	-I	+I
	R	Max	10	+I	-I	+I
	S	Min	10	+I	-I	+I
	T	Max	10	+I			15
	S	Min	10	+I	-I	15
	V	Max	10	+I			2
	S	Min	10	+I	-I	2	2
	R	Max	10	+I	2	+I
	Y	Min	10	+I	-I	+I
	W	Max	10	+I			4
	Y	Min	10	+I	-I	4	4
	R	Max	10	+I	4	+I	4
	Q	Min	10	+I	-I	4	4
	A	Max	-I	+I	10	4	10

Efficiency of the Alpha-Beta Procedure

Games that Involve Chance

Cutting off Search

Non-Quiescent Nodes

Horizon Effect

Iterative Deepening