# Alpha beta pruning example. Alpha Beta Pruning in Minimax Algorithm 2022-11-02

Alpha beta pruning example Rating: 7,7/10 163 reviews

Alpha beta pruning is a technique used in game tree search algorithms to improve their efficiency. It is a way of trimming the search tree by pruning branches that cannot possibly affect the final outcome of the search. This is done by maintaining two values, alpha and beta, which represent the minimum and maximum scores that the current player is assured of, based on the current state of the game.

For example, consider a game of tic-tac-toe where one player is "X" and the other is "O". The game tree for tic-tac-toe is relatively small, as there are only a few possible moves at each turn. However, the game tree for a more complex game such as chess or Go is much larger and more difficult to search through.

In the alpha beta pruning algorithm, the search tree is traversed in a depth-first manner, and at each node, the algorithm compares the alpha and beta values to determine whether the current branch can be pruned. If the alpha value is greater than or equal to the beta value, then the current branch can be safely pruned because the player whose turn it is cannot possibly achieve a score better than the alpha value.

Let's consider an example of alpha beta pruning in a tic-tac-toe game. Suppose that it is X's turn, and X has the following possible moves:

• X can place an "X" in the top left corner of the board, resulting in a score of 1 for X.
• X can place an "X" in the top middle of the board, resulting in a score of 1 for X.
• X can place an "X" in the top right corner of the board, resulting in a score of 1 for X.

At this point, the alpha value is 1, because X has already achieved a score of 1 by placing an "X" in the top left corner. The beta value is -1, because O has not yet had a chance to play and therefore has not achieved a score.

Suppose that O now has the following possible moves:

• O can place an "O" in the middle left of the board, resulting in a score of -1 for O.
• O can place an "O" in the middle middle of the board, resulting in a score of -1 for O.
• O can place an "O" in the middle right of the board, resulting in a score of -1 for O.

At this point, the alpha value is still 1, and the beta value is -1. However, because the alpha value is greater than or equal to the beta value, the algorithm can prune the branches corresponding to O's moves, as they cannot possibly result in a score better than -1 for O. This saves significant time and resources, as the algorithm does not have to search through these branches.

In conclusion, alpha beta pruning is a powerful technique for improving the efficiency of game tree search algorithms. By pruning branches that cannot possibly affect the final outcome of the search, the algorithm can save significant time and resources, making it more practical to use in complex games such as chess or Go.

## Minimax search and alpha Move ordering plays an important role in alpha beta pruning. For every legal position it is possible to effectively determine all the legal moves. So, each MAX node has? The value of node B is also 5 So far this is how our game tree looks. Stockfish is a mature implementation that is rated as one of the strongest chess engines available today as evidenced by it winning the Top Chess Engine Championship in 2016 and 2017. Alpha is the best value that the maximizer currently can guarantee at that level or above. This method allows us to ignore many branches that lead to values that won't be of any help for our decision, nor they would affect it in any way. Look at Move Ordering in Pruning The effectiveness of alpha — beta pruning is based on the order in which node is examined.

Next

## Minimax Algorithm in Game Theory But, that algorithm could still be optimised further. B now calls E to see if he can get a lower value than 5. It is necessary that the evaluation function contains as much relevant information as possible, but on the other hand - since it's being calculated many times - it needs to be simple. Immediately above it, is a maximiser node, who already visited the? So, without further ado, let's start! What is the purpose of alpha-beta pruning in Min-Max algorithm explain with example? Opening books are exactly this - some nice ways to trick an opponent in the very beginning to get advantage, or in best case, a win. Note the nodes with value -9. In order to do that, I played out all possibilities in my head, and am now trying to predict how you will play. If I want to examine the positions in the second row, now I have to think like you! For that reason it is not a good practice to explicitly create a whole game tree as a structure while writing a program that is supposed to predict the best move at any moment.

Next

## What is alpha Therefore, when I examine the second row, I need to figure out what's the worst-case scenario, for me, for each position. In this case, it also consumes more time because of alpha-beta factors, such a move of pruning is called worst ordering. This node returns a value of 3. When it is your turn, the circle has an arrow pointing down: that's because you want to decrease my score as much as possible. This gives us the following pseudo-code procedure for minimax evaluation of a game tree. If not, re-read it carefully, grab a pen and a piece of paper, and make the drawings, the arrows, etc.

Next

## Minimax with Alpha So it breaks and it does not even have to compute the entire sub-tree of G. Now, what we need to do is test our generic minimax function. Let's assume that every time during deciding the next move we search through a whole tree, all the way down to leaves. Moving down the game tree represents one of the players making a move, and the game state changing from one legal position to another. Shortly after, problems of this kind grew into a challenge of great significance for development of one of today's most popular fields in computer science - artificial intelligence. Because, when I go down the tree, I want to call the function recursively. Now, C will return the node value to A and the best value of A will be MAX 1, 3 will be 3.

Next

## Artificial Intelligence To demonstrate this, 10 120 possible games. In chess, players can generally make plenty of different moves, which means that the trees that I have been drawing would get very huge, very fast. At leaf nodes we return the appropriate values. Since we cannot eliminate the exponent, but we can cut it to half. We define a function evaluate that can be applied to a leaf state to determine which of these values is correct. Minimax algorithm Minimax is a classic depth-first search technique for a sequential two-player game.

Next

## Alpha Beta Pruning in AI What is the condition of alpha-beta pruning? The article will introduce the theoretical concepts needed to understand the minimax algorithm, as well as the alpha-beta pruning optimisation. Even searching to a certain depth sometimes takes an unacceptable amount of time. It is an optimization technique for the minimax algorithm. If the value is equal or greater than the current? The minimax value of a node is the utility of the node if it is a terminal node. That is, we want to implement these algorithms so that we can use them as artificial intelligence algorithms to play games against humans. In the next step the algorithm again comes to node A from node B.

Next

## Alpha So far, we only applied the minimax algorithm to very small trees. Minimax search Suppose that we assign a value of positive infinity to a leaf state in which we win, negative infinity to states in which the opponent wins, and zero to tie states. For example, if I decide to make the middle move, what would you do in response? As a result of deleting these nodes, the algorithm becomes more efficient. Alpha-beta pruning is nothing but the pruning of useless branches in decision trees. In that tree, some useless branches increase the complexity of the model. The one that makes me lose, obviously! What is the difference between mini max algorithm and alpha-beta pruning? These same values will be transferred to node F.

Next

## aplha beta pruning opportunities.alumdev.columbia.edu Finally, this diagram brings some clarity! So, for this example the optimal value of the maximizer will be 3. Slow down and re-read the paragraph above, please. So, I play out these three moves inside my head, and I see that none of the moves gives me a win. Now, I need to evaluate the game positions in the third row. For example, what if we managed to avoid traversing certain parts of the tree, if we know those parts are irrelevant? If you only want to watch one, I recommend you watch The minimax algorithm The minimax algorithm is the algorithm around which this whole article revolves, so it is best if we take some time to really understand it.

Next

## Minimax algorithm and alpha Now, we need to turn it into something objective, so that we can translate it into code. As for upper and lower bounds, all you know is that it's a number less than infinity and greater than negative infinity. For trees of this size, the algorithm has no trouble going through the whole tree. Now, we can call the minimax function with the previous tree, and see what we get. On top of this, we will be taking a look at these algorithms from the perspective of a game. Pruned parts of the tree are marked with X. P will move to explore the next part only after comparing the values with the current? Hence by removing these nodes algorithm becomes fast.

Next

## Alpha Beta Pruning in Minimax Algorithm In short, it is a lot of work to traverse the whole tree. Each complete game tree has as many nodes as the game has possible outcomes for every legal move made. What does this mean? Photo by Faye Cornish on Unsplash Introduction This article aims at providing the reader with an introduction to the minimax search algorithm, and to alpha-beta pruning — an optimisation over that same algorithm. . Let, P be the player who will try to win the game by maximizing its winning chances.

Next