// basic Alpha-Beta search;
move bestmove;
int alphabeta(int depth, int alpha, int beta, bool isMyTurn) ...{
if (gameOver || depth == 0) ...{
return evaluation();
}
generateLegalMoves();
// you may change the search order to make the search faster
for (each move m) ...{
do move m;
score = -alphabeta(depth - 1, -beta, -alpha, ! isMyTurn );
if (score > alpha) ...{
alpha = score;
if(at the Level 1)
bestmove = m;
}
undo move-m;
if (alpha >= beta) ...{
break;
}
}
return alpha;
}
Initial call : alphabeta(depth, - infinite, infinite, isMyTurn);
不理解上面的代码的话,看看下面的极小极大搜索
极小极大搜索
//极大搜索
int Max(int depth)
...{
int best = -INFINITY;
if (depth == 0)