Pawn
Captures Wyvern: How Computer Chess Can Improve Your Pathfinding
Listing
1. The Code For The Minimax Algorithm
int Maximize(position
p) {
int
numOfSuccessors; /* total moves */
int gamma; /*
current maximum */
int i; /*
move counter */
int sc; /* score returned
by search */
if
(EndOfGame(p)) { return GameValue(p)); }
gamma = -4;
numOfSuccessors = GenerateSuccessors(p);
for (i=1; i <= numOfSuccessors; i++) {
sc = Minimize(p.succ[i]);
gamma = max(gamma, sc);
}
return (gamma);
}
int Minimize(position
p) {
int
numOfSuccessors; /* total moves */
int gamma; /*
current maximum */
int i; /*
move counter */
int sc; /* score returned
by search */
if
(EndOfGame(p)) { return GameValue(p)); }
gamma = +4;
numOfSuccessors = GenerateSuccessors(p);
for (i=1; i <= numOfSuccessors; i++) {
sc = Maximize(p.succ[i]);
gamma = min(gamma, sc);
}
return (gamma);
}
________________________________________________________
Back
to Article