Table of Contents

Chess - Programming - Search - Negamax

Negamax is a common way of implementing Minimax and derived algorithms.


How to Use NegaMax

NegaMax is called from a root function.

In the loop which generates all the root moves:


max(a, b) == -min(-a, -b)

This is how the pseudo-code of the recursive algorithm looks like. For clarity move making and unmaking is omitted.

int negaMax( int depth ) {
    if ( depth == 0 ) return evaluate();
    int max = -oo;
    for ( all moves)  {
        score = -negaMax( depth - 1 );
        if( score > max )
            max = score;
    }
    return max;
}

NOTE: In order for NegaMax to work, the Static Evaluation function must return a score relative to the side to being evaluated.

  • This score must be symmetric.
    • The simplest score evaluation could be: score = materialWeight * (numWhitePieces - numBlackPieces) * who2move where who2move = 1 for white, and who2move = -1 for black.

References

http://web.archive.org/web/20120209042116/http://chessprogramming.wikispaces.com/Negamax