score minimax(state s, int n)
if (n = 0 OR s is a terminal node)
{
if win position for program
return +inf;
if loss position for prg
return -inf;
if draw game
return 0;
return f(s); // static eval. func @ s
}
else
bestscore = prg's move ? -inf : +inf;
for each successor state s' of s
{
v= minimax(s’ n-1);
if programs move
bestscore = max(v, bestscore);
else
bestscore = min(v, bestscore);
}
return bestscore;
}
Create an array which is equal to the size of n players. Run the minimax algorithm from the perspective of each player and fill the appropriate array entry with their evaluation.
int playerevals[4], i;
for(i = 0; i < 4; ++i)
{
//run the minimax
playerevals[i] = minimax();
}
In the minimax, you'll obviously have to change the evaluation to analyze from the perspective of each player. So it will be like:
1 2 3 4 5 6
//Pseudocode
on player 1 pass...
if win position for player 1
score = some really high number
if win position for any other player
score = some really low number.