Question

I'm having trouble understanding this pseudocode I found for alpha beta pruning on wikipedia:

function alphabeta(node, depth, α, β, Player)         
    if  depth = 0 or node is a terminal node
        return the heuristic value of node
    if  Player = MaxPlayer
        for each child of node
            α := max(α, alphabeta(child, depth-1, α, β, not(Player)))     
            if β ≤ α
                break (* Beta cut-off *)
        return α
    else
        for each child of node
            β := min(β, alphabeta(child, depth-1, α, β, not(Player)))     
            if β ≤ α
                break (* Alpha cut-off *)
        return β

What is confusing me is the if Player = MaxPlayer condition. I understand the whole recursively calling the function with not(Player) to get the minimum value, which will then recursively call the function with Player, repeating until the depth limit is reached or a goal state has be found. However, I don't understand the

if β ≤ α
    break 

statement. My understanding of that is that, the second value higher than the minimum value found in the previous call (β) is found, that is the value that is used. But since this is the MAX part of the function, don't we want the HIGHEST value, not just ANY value that is greater than beta?

Was it helpful?

Solution

This is the trimming phase of the algorithm, in the MaxPlayer clause (When checking for max value for the player in this node):

Beta is the parameter of the function which is the "trimming factor". It represents the minimum score you have found so far. It means that the parent of the current node, which is a minimizing node - has already found a solution which is beta.

Now, if we continue iterating all children, we will get something at least as good as the current alpha. Since beta <= alpha - the parent node - which is minimizing node - will NEVER chose this alpha (or any value greater than it) - it will chose a value which is beta or lower - and the current node has no chance of finding such, so we can trim the calculation.

Example:

     MIN
    /   \
   /     \
  /       \
 /         \
5          MAX
          / | \
         /  |  \
        /   |   \
       6    8    4

When evaluating the MAX node, we will return 8, if we apply the normal min-max algorithm. However, we know that the MIN function is going to do min(5, MAX(6, 8, 4)). Since after we read 6 we know max(6, 8, 4) >= 6, we can return 6 without continuing computations because the MIN computation of the upper level will be min(5, MAX(6, 8, 4)) = min(5, 6) = 5.

This is the intuition for one level, it is of course done recursively to "flow" to all levels with the same idea.

The same idea holds for the trimming condition in the MIN vertex.

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