Dealing with loops in game trees - Part 2

In Part 1 I introduced negamax graphs and an algorithm for calculating unique lower and upper bounds on the values of the nodes. In Part 2 we're going to look at partial graphs and strategies for expanding them in order to arrive at the final bounds with minimal effort.

Let's start with an example.

Here we have a fully expanded negamax game tree. Let's work out the minimally expanded tree to establish the lower bound of the root node. For that we need to establish an upper bound on one of the children.
The minimally expanded tree to establish an upper bound requires lower bounds on all of the children.
Because the lower and upper bounds match we get the final minimally expanded tree by combining the above two.
You can verify that no matter what value you put in the question marks the value at the top is not going to change.

So that works out for trees. Establish lower and upper bounds, see that they are the same and you're done. Doesn't work for loops though. In Part 1 we saw a game graph with distinct lower and upper bounds. So how do we know that the answer we got was final? The obvious answer is that we had the graph fully expanded. The bounds couldn't change because the graph couldn't change.

We can do better though. It is possible to prove that the lower and upper bounds of a node are final even in a partially expanded graph. Here's how:

  1. The lower bound of a node is final if all child nodes with -lower bound higher than the node's lower bound have final upper bounds.
  2. The upper bound of a node is final if it has a child node with a final -lower bound equal to the node's upper bound.
  3. If the lower and upper bound of a node are equal they are both final.
Great, a recursive definition. So how does this work? Let's try applying this to a loop.
It's obvious that the leaf nodes are final (by 3. above), but what about nodes A and B (hover over the nodes or click on them to see the labels)? Does A have a final lower bound? By 1. above that depends on if B has a final upper bound. By 2. above that then depends on if A has final lower bound. So if A does indeed have final lower bound it has a final lower bound. On the other hand if A doesn't have a final lower bound it doesn't have a final lower bound. Both states of affairs are consistent so which one is true?

The trick is to assume that every node with children has final lower and upper bounds. Then we just need to see if the assuptions hold using the nodes without children. There are optimizations to this but for now let's be content with this algorithm.

  1. For all nodes with equal lower and upper bounds set their bounds as final and remove them from consideration.
  2. Set the lower and upper bounds of every node (in consideration) without children as final.
  3. If a node has a child with non-final upper bound and -lower bound higher than the node's lower bound then set the node's lower bound as not final.
  4. If all children with -lower bound equal to a node's upper bound have non-final lower bounds then set the node's upper bound as not final.
  5. Repeat steps 3. and 4. until nothing changes.

Here we have a negamax graph expanded so that the nodes of interest are only half final.

Node A has a final upper bound because it always has the choice of staying in the loop with B and B only has the choice of staying in the loop or falling back getting the low value of -2. Node C doesn't matter for A because A cannot hope to get a better result from it and because A can stay in the loop it cannot get a worse result either. Likewise B has a final lower bound because A can force B into a loop until it gives in and there's only one final way to give in. Node A doesn't have a final lower bound because if we put the value of 2 or higher in the question marks it would raise the lower bound of A to 2. The lower bound can change so it isn't final. This also means that B doesn't have a final upper bound. For now B can hope to stay in the loop and force A into choosing the low value of 1, but this hope is not guaranteed.
Revealing that node C has a lower bound of 0 finalizes the lower bound of node A into 1. Node A cannot do any better now. This also means that the upper bound of B is final. Notice that it doesn't matter what you put in the question mark. The values of A and B are not going to change.

Finally let's go through a "real" example. For this purpose I've invented a game that goes as follows:

Notice that this game has an infinite state space if both players decide to keep adding numbers. It is therefore impossible to expand the whole graph and we need other criteria for deciding when we have expanded enough to get the final answer.

Here we have the root node, the number 13. We don't know anything about it yet so its values could be anything.

Note that you can hover over the nodes or click on them to see which number they represent.

Click the button to proceed.

This concludes Part 2. In Part 3 we're going to look at implementations and consider computationally effective strategies for arriving at the final values of a node in a negamax graph.