In addition to
Percepied's writeup, here's a quick'n'dirty
pseudocode algorithm for alpha-beta pruning:
minimax-value max-value(gamestate, alpha, beta)
{
if(cutoff-test(gamestate)) return eval(gamestate)
for each s in successors(gamestate)
{
alpha = max(alpha, min-value(s, alpha, beta))
if(alpha >= beta) return beta
}
return alpha
}
minimax-value min-value(gamestate, alpha, beta)
{
if(cutoff-test(gamestate)) return eval(gamestate)
for each s in successors(gamestate)
{
beta = min(beta, max-value(s, alpha, beta))
if(alpha >= beta) return alpha
}
return beta
}
Note that the return values of both functions is a minimax value for a state. You should probably have a separate function that goes through each successor state of a particular gamestate and assigns it the return value of min-value(state, alpha, MAX) (the reason for the MAX constant is so that the first value min-value looks at will be assigned to beta. This also means that this external function's first call to min-value will be min-value(state, MIN, MAX); after this, the function will keep track of a best-value alpha and pass that instead of MIN). Also note that in general, the cutoff test is a ply-depth a la depth-limited search, so an additional variable ply may need to be passed along and decremented (or incremented, depending on your implementation) at each function.