0

I am trying to apply the alpha beta pruning algorithm to this given tree.

enter image description here

I am stuck when I hit node C because after expanding all the children of B, I give A >= -4, I then expand C to get I =-3, which IS greater than -4 (-3 >= -4). Do I therefore, update A to -3? If so do I then afterwards, prune J and K because -3 >= -3 ? When I worked through the example, I pruned, J, K, M and N. I am really uncertain about this =(

EDIT:

Another question: After exploring B and passing the value of B to A, do we pass this value to C and thus to I? I saw an example that this was the case. Here it is: http://web.cecs.pdx.edu/~mm/AIFall2011/alphabeta-example.pdf

However, in this example, http://web.cecs.pdx.edu/~mm/AIFall2011/alphabeta-example.pdf, it doesn't seem to pass down values, instead it seems to only propagate values upwards. I am not sure which one is correct or if it makes a difference at all.

Johnathan Au
  • 5,244
  • 18
  • 70
  • 128

2 Answers2

2

After expanding all the children of B, then A has α=-4, β=∞.

When you get to I, then α=-4, β=-3. α < β so J and K are not pruned. They would need to be evaluated to make sure that they're not less than -3, lowering the evaluation of C. The value of A is updated to α=-3, β=∞ after C is expanded. You can't use the updated alpha value of A when evaluating J because it wouldn't have been updated yet.

J and K would be pruned if I was -5 instead. In that case it wouldn't matter what J and K are because we already know the evaluation of C is worse than B because -5 < -4, and J and K can only make that worse.

Each node passes the alpha and beta values to its children. The children will then update their own copies of the alpha or beta value depending on whose turn it is and return the final evaluation of that node. That is then used to update the alpha or beta value of the parent.

See Alpha-Beta pruning for example:

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 β

// Initial call
alphabeta(origin, depth, -infinity, +infinity, MaxPlayer)
fgb
  • 18,439
  • 2
  • 38
  • 52
  • Hmmm, thank you. I'm still unsure about what happens when we're passing values from the root node to it's children. We got C node expanded now and we have found that the lowest value is -3 and we update the root node to -3 also because this is the highest so far. What then do we do with -3 in node D? Do we pass it onto node D and we use it to evaluate it's children such that it asks are the children <= -3, with which we find that node L is -4 so we update node D to -4 because -4 <= -3. But the after that -3 >= -4 from the root node and so we prune of M and N? Have I got this right? :S – Johnathan Au Dec 30 '12 at 03:45
  • 1
    Yes, the alpha value of A is -3, which is passed to D. D finds a beta value of -4 so prunes M and N. – fgb Dec 30 '12 at 03:52
  • Ahhh, see this is what I don't get. Going back to node C after fully expanding node B. We have root A that is >=-4. It passes it down to C node which asks <=-4. But then, I, J and K are not less than -4... – Johnathan Au Dec 30 '12 at 03:58
  • 1
    What would you expect to happen if I, J, K are not less than -4? C will check if any values are <= -4 in order to prune the tree. If no values are <= -4, then there's no pruning and the smallest value is returned to A. – fgb Dec 30 '12 at 04:12
  • But -4 >= -3... I'm so confused! I don't understand how it can update C node's <=-4 with <=-3 because of the -3 <= -4. – Johnathan Au Dec 30 '12 at 04:17
  • 1
    Try writing separate alpha and beta values. C has an alpha of -4 from its parent, and a beta of -3 from its children, so alpha < beta. – fgb Dec 30 '12 at 05:07
0

Whenever I need to refresh my understanding of the algorithm I use this: http://homepage.ufp.pt/jtorres/ensino/ia/alfabeta.html

You can enter your tree there and step through the algorithm. The values you would want are:

3 3 3 3

-2 -4 3 etc.

I find that deducing the algorithm from an example provides a deeper understanding.

Reasurria
  • 1,808
  • 16
  • 14