Minimax is an algorithm used to determine the score in a zero-sum game after a certain number of moves, with best play according to an evaluation function.
int maxi( int depth ) { if ( depth == 0 ) return evaluate(); int max = -oo; for ( all moves) { score = mini( depth - 1 ); if( score > max ) max = score; } return max; } int mini( int depth ) { if ( depth == 0 ) return -evaluate(); int min = +oo; for ( all moves) { score = maxi( depth - 1 ); if( score < min ) min = score; } return min; }