0

I am implementing an AI for an Othello game using MiniMax with Alpha Beta pruning. I have implemented an Alpha Beta algorithm that tells me the value that I can obtain, but not which node it is that I should select? So my question is how can I use Alpha-Beta to tell me which node I should select, not what the resultant value would be. Here is the pseudocode for my Alpha-Beta algorithm.

01 function alphabeta(node, depth, α, β, maximizingPlayer)
02      if depth = 0 or node is a terminal node
03          return the heuristic value of node
04      if maximizingPlayer
05          v := -∞
06          for each child of node
07              v := max(v, alphabeta(child, depth – 1, α, β, FALSE))
08              α := max(α, v)
09              if β ≤ α
10                  break (* β cut-off *)
11          return v
12      else
13          v := ∞
14          for each child of node
15              v := min(v, alphabeta(child, depth – 1, α, β, TRUE))
16              β := min(β, v)
17              if β ≤ α
18                  break (* α cut-off *)
19          return v
  • _not what the resultant value would be_ - but you need that as well. You need to return 2 things. An exact answer would depend on the definition of your `node` , programming language etc. – H H Dec 31 '16 at 16:21
  • @HenkHolterman Why do I need to return the resultant value? If my tree was a binary search tree for example, I would just need to know which of the 2 nodes to select, not what the value was? Of course though I'll need that value to determine which node to select – Matthew Fennell Dec 31 '16 at 17:26
  • You just answered yourself: "to determine which ..." – H H Dec 31 '16 at 17:31
  • I don't think you understand my question. The algorithm determines which path to take and gets the correct result that should be obtained. I just need to backtrack to find out which was the initial node it selected, but as I only have the end result, how can I know the path to the node with that value? – Matthew Fennell Dec 31 '16 at 18:17

1 Answers1

0

If you only want to know the best move in the root position, it is enough to remember which move in the root position had the highest score. For that, just returning the score is enough. No change in the pseudo-code is necessary.

As you are asking about the path to the critical node, I guess you are asking about a way to reconstruct the principal variation, which gives insights about the series of moves that the search expected.

In theory, you can just return the value and the principal variation from the recursive call. That allows you to reconstruct the path. Triangular PV-Tables are data structures optimized for that purpose.

If your search uses a transposition table, a simpler approach is just to start the root position and look up the best move in the transposition table. Then make that move and repeat (look up the best move, make the best move, lookup again, etc.) until the game is over or no entry has been found. In the end, the moves that were made are the principal variation.

The transposition table approach is not as precise as explicitly keeping track of the principal variation, but it is simple to implement and adds no overhead during the search.

Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239
  • Just to clarify, a transposition table can add significant overhead (less so if you use Zobrist hashing). But, this cost is usually far outweighed by reduction in the size of the search tree. – Nathan S. Jan 03 '17 at 06:34
  • @NathanS. True. "No overhead" assumes that the search already uses a transposition table but so far, I have not seen an optimized Alpha Beta search without transposition tables. At least in chess, every engine uses it, mostly to improve move ordering. I think the same goes for other similar games (e.g, Reversi). – Philipp Claßen Jan 04 '17 at 16:23
  • @PhillipClaßen Very true - the only game where you wouldn't use the transposition table is where there are very few transpositions. – Nathan S. Jan 06 '17 at 04:42