Minimax Search with Alpha-Beta Pruning

ALPHA-BETA(state, player, depth, alpha, beta)

/*
alpha is the highest score achievable by MAX along the path to state
beta is the lowest score achievable by MIN along the path to state
*/

If the level is the top level, let alpha = -infinity, beta = +infinity

If state is a terminal state, or if depth has reached the search limit:
    apply evaluation function
to state and return result

If player is MAX:

    Until all of state's children are examined with ALPHA-BETA or until
    alpha is equal to or greater than beta:

             Call ALPHA-BETA(child, MIN, depth+1, alpha, beta)
             and note result

          Compare the value reported to alpha; if reported value
             is larger, reset alpha to the new value

     Return largest value reported

If player is MIN:

    Until all of state's children are examined with ALPHA-BETA or until
    alpha is equal to or greater than beta:

             Call ALPHA-BETA(child, MAX, depth+1, alpha, beta)
             and note result

          Compare the value reported to beta; if reported value
             is smaller, reset beta to the new value

     Return smallest value reported