1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
MoveScore abNegascout(vector<vector<char> > &board, int ply,
int alpha, int beta, char piece)
{
if (ply==mMaxPly) {
return MoveScore(evaluation.evaluateBoard(board, piece, oppPiece));
}
int currentScore;
int bestScore = -INFINITY;
MoveCoord bestMove;
int adaptiveBeta = beta;
vector<MoveCoord> moveList =
evaluation.genPriorityMoves(board, piece,
findValidMove(board, piece, false));
if (moveList.empty()) {
return MoveScore(bestScore);
}
bestMove = moveList[0];
for(int i=0;i<moveList.size();i++) {
MoveCoord move = moveList[i];
vector<vector<char> > newBoard;
newBoard.insert( newBoard.end(), board.begin(), board.end() );
effectMove(newBoard, piece, move.getRow(), move.getCol());
// First Call ******
MoveScore current = abNegascout(newBoard, ply+1, -adaptiveBeta,
-max(alpha,bestScore), oppPiece);
currentScore = - current.getScore();
if (currentScore>bestScore){
if (adaptiveBeta == beta || ply>=(mMaxPly-2)){
bestScore = currentScore;
bestMove = move;
}else {
// Second Call ******
current = abNegascout(newBoard, ply+1, -beta,
-currentScore, oppPiece);
bestScore = - current.getScore();
bestMove = move;
}
if(bestScore>=beta){
return MoveScore(bestMove,bestScore);
}
adaptiveBeta = max(alpha, bestScore) + 1;
}
}
return MoveScore(bestMove,bestScore);
}
|