• in game playing between two opponent players. The state space represents the possible turns of both players. Each level of the search space denotes the possible turn of one player only. • consider games in which the players alternate making moves and try to maximize (or minimize) a scoring function (also called utility function). • For simplification, only consider games with the two properties:
• Two player – no coalitions, etc. • Zero sum - one player's win is the other's loss; no cooperative victories

. • The game tree consists of all possible moves for the current players starting at the root and all possible moves for the next player as the children of these nodes. 0 with a draw and -1 with a loss for MAX. and so forth. a loss. • Each terminal position has a score. called the MIN player. tries to minimize the score. as far as desired. E.Game Trees • represent games as a tree where nodes represent current state of the game and arcs represent the moves. • Example : Game of Tic-Tac-Toe . • The leaves represent terminal positions where the outcome of the game is clear (a win. • Each individual move by one player is called a "ply".g. High scores are good for one of the players. The other player. called the MAX player. we may associate 1 with a win. a draw).

section of a game tree for tic tac toe .

we will give each position which is favorable for player 1 a positive number (the more positive. In our example.B. and 0 for a draw. we will give each position which is favorable for player 2 a negative number. • N. Similarly. player 1 is 'X'. player 2 is 'O'. .: The blue scores are the only ones that can be computed by looking at the current position. -1 for a win by 'O'.Tic-tac-toe • To score each position. the more favorable). and the only three scores we will have are +1 for a win by 'X'.

if it is a MINIMIZER node. or the success of the MAXIMIZER respectively. draw. do Begin if it is a MAXIMIZER node.0. Expand the entire state-space below the starting node.+1}. End For. Assign values to the terminals of the state-space from {-1. then its value will be the minimum of its children. 3.MINIMAX • algorithm for computing the best next move in games Begin 1. . depending on the success of the MINIMIZER. 2. then its value will be maximum of its children‘s values. For each node whose all children possess values. End.

-The computation process is illustrated next-> . greater than zero. normally 7 or 9. -The game will come to an end when either of the two players cannot give a successful move. -According to standard convention we name the two players MINIMIZER and MAXIMIZER. is called the MINIMIZER. For a game such as tic-tac-toe. called a pile.MINIMAX example: NIM game -played between two players. -Each player in his turn has to break a single pile into two piles of unequal sticks. The player who cannot give a successful move the first time will lose the game. placed on a single row. here. NIM is a defensive game and consequently the opening player. where the opener always gets the benefit. -starts with an odd number of match sticks. the opening player is called the MAXIMIZER.

.

minimax will simply return the score of the board. then there is nothing to compute. minimax will go through each possible child. • Otherwise. and the board with the most negative score for player 2. and (by recursively calling itself) evaluate each possible move.MINIMAX Evaluation • If game finishes in the given position. the best possible move will be chosen. where ‘best’ is the move leading to the board with the most positive score for player 1. Then. .

not too long . the running time is prohibitively expensive. This is often done using an evaluation function. Of course. . -For a game like Chess however. by the time we finish analyzing a move the sun will have gone nova and the earth will no longer exist! Therefore. now the program must determine whether a certain board position is 'good' or 'bad' for a player. not to the end of the game. In fact.MINIMAX Evaluation How long does this algorithm take? -For a simple game like tic tac toe.can search all possible positions. but only a few moves ahead. This function is the key to a strong computer game. all real computer games search.

to select a current move by the same player.MINIMAX Limitations -MINIMAX requires expanding the entire statespace. -an alternative approach is to evaluate heuristically the status of the next ply move of the player. especially for problems with a large state-space. -a severe limitation. -Consider tic-tac-toe for demonstration-> .

where M (n) = number of my possible winning lines. Formally. e(n) = M (n) . M (n) =6 . . in the fig. For example. and O (n) = number of opponent’s winning lines.O (n).Consider a heuristic function e(n) at node n that evaluates the difference of possible winning lines of the player and his opponent. O (n) = 5 and hence e(n) = 1..

the values are estimated following the MINIMAX algorithm. . whereas the beta value of the MIN nodes cannot increase. Now. Alpha represents the minimum score that the maximizing player is assured of and beta represents the maximum score that the minimizing player is assured of.Prior to the process of computing MAX / MIN of the backed up values of the children. . . . the algorithm estimates e(n) at all fringe nodes n.Alpha and beta denote two cutoff levels associated with MAX and MIN nodes. -two extra ply of movements are considered to select the current move from alternatives. which does not require expansion of the entire space exhaustively.The Alpha-Beta Cutoff Procedure -a new type of algorithm. They are the backed up values up to the root like MINIMAX.The alpha value of MAX nodes cannot decrease.

. If yes. If yes. it means that the current position cannot be the result of best play by both players and hence need not be explored further). prune that path below the MIN node (when beta becomes less than alpha. prune the nodes below the MAX node. check whether i) the beta value of any MIN node below a MAX node is less than or equal to its alpha value. ii) the alpha value of any MAX node below a MIN node exceeds the beta value of the MIN node.Pruning To prune the unnecessary paths below a node.

ii) Compute e(n) for all leaf (fringe) nodes n in the tree. . else expand the existing tree by depth first manner. estimate the maximum of the values (e or β) possessed by the children of a MAXIMIZER node N and assign it its α’min value. Similarly. the tree should be expanded at least up to a depth (d + 2). iii) Compute α’min (for max nodes) and β’max values (for min nodes) at the ancestors of the fringe nodes by the following guidelines: Estimate the minimum of the values (e or α) possessed by the children of a MINIMIZER node N and assign it its β’max value. if it is the beginning move. To make a decision about the selection of a move at depth d.steps in the α-β search algorithm i) Create a new node.

N. on the other hand. then their current αmin value = Max (αmin value. v) If the estimated βmax value of a MINIMIZER node N is less than the αmin value of its parent MAXIMIZER node N’ then there is no need to search below the MINIMIZER node N.: The above five steps constitute a pass. if the MINIMIZER nodes already possess βmax values.B. then their current βmax value = Min (βmax value. Similarly. β’max). if the αmin value of a MAXIMIZER node N is more than the βmax value of its parent node N’ then there is no need to search below node N. . Continue the steps until the game is over.Steps contd. α’min). iv) If the MAXIMIZER nodes already possess αmin values.

Demonstration .

.

.

Thank you Have a Nice Day. .