Chess - Programming - Alpha-Beta Pruning

Alpha-Beta pruning is not actually a new algorithm, rather an optimization technique for minimax algorithm.

Alpha is the best value that the maximizer currently can guarantee at that level or above.

Beta is the best value that the minimizer currently can guarantee at that level or above.


Alpha-beta pruning is most effective on strongly-ordered trees, where the best move is searched first, the second-best move is searched second, and so on up to the worst move which is searched last.

Conversely, on a tree in the exact opposite order, alpha-beta is no better than naive Negamax Search.


A program to illustrate Alpha-Beta Pruning

Example

Transposition Table enhanced Alpha-Beta


Pseudocode

function minimax(node, depth, isMaximizingPlayer, alpha, beta):
 
  if node is a leaf node :
    return value of the node
 
  if isMaximizingPlayer :
    bestVal = -INFINITY 
    for each child node :
      value = minimax(node, depth+1, false, alpha, beta)
      bestVal = max( bestVal, value) 
      alpha = max( alpha, bestVal)
      if beta <= alpha:
        break
      return bestVal
 
  else :
    bestVal = +INFINITY 
    for each child node :
      value = minimax(node, depth+1, true, alpha, beta)
      bestVal = min( bestVal, value) 
      beta = min( beta, bestVal)
      if beta <= alpha:
        break
      return bestVal
 
 
// Calling the function for the first time.
minimax(0, 0, true, -INFINITY, +INFINITY)