(^214) | Chapter 7: Path Finding in AI
Figure 7-18. NegMax fact sheet
Example 7-7. NegMax implementation
public class NegMaxEvaluation implements IEvaluation {
IGameState state; /* State to be modified during search. /
int ply; /* Ply depth. How far to continue search. /
public NegMaxEvaluation (int ply) {
this.ply = ply;
}
public IGameMove bestMove (IGameState s,
IPlayer player, IPlayer opponent) {
this.state = s.copy( );
MoveEvaluation me = negmax(ply, player, opponent);
return me.move;
}
public MoveEvaluation negmax (int ply, IPlayer player, IPlayer opponent) {
// If no allowed moves or a leaf node, return board state score.
Iterator
if (ply == 0 || !it.hasNext( )) {
Algorithms in a Nutshell
Algorithms in a Nutshell By Gary Pollice, George T. Heineman, Stanley Selkow ISBN:
9780596516246 Publisher: O'Reilly Media, Inc.
Prepared for Ming Yi, Safari ID: [email protected]
Licensed by Ming Yi
Print Publication Date: 2008/10/21 User number: 594243
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
Licensed by
Ming Yi
tina meador
(Tina Meador)
#1