int Agent<Reversi>::minMaxAlphaBeta(Reversi& currentGame, unsigned int depth, int alpha, int beta) { if(depth >= maxDepth || currentGame.actionBegin() == currentGame.actionEnd()) { return heuristic(currentGame); } Reversi tempGame; int score, actionCounter = 0, bestAction = 0; if(depth%2 == 0) { for(Action iter = currentGame.actionBegin(); iter != currentGame.actionEnd(); iter++) { tempGame = currentGame; tempGame.play(iter); score = minMaxAlphaBeta(tempGame,depth+1,alpha,beta); if(score > alpha) { bestAction = actionCounter; alpha = score; } if(alpha>=beta) { bestAction = actionCounter; return alpha; } actionCounter++; } if(depth == 0) { return bestAction; } else { return alpha; } } else { for(Action iter = currentGame.actionBegin(); iter != currentGame.actionEnd(); iter++) { tempGame = currentGame; tempGame.play(iter); score = minMaxAlphaBeta(tempGame,depth+1,alpha,beta); if(score < beta) { bestAction = actionCounter; beta = score; } if(alpha>=beta) { bestAction = actionCounter; return beta; } actionCounter++; } if(depth == 0) { return bestAction; } else { return beta; } } }
void testCallByReference2(Reversi &reversi){ int coorX, coorY; int size=6; cout << "__________CALL BY REFERENCE TEST FUNCTION____________\n"; cout << "-----GAME1------" << endl << reversi << endl; reversi.resizeTheBoard(size); cout << "The board resizing to " << size << "x" << size << " board." << endl; cout << reversi << endl; cout << "Please enter correct moves for good testing.\n"; reversi.getCoordinates(coorX, coorY); reversi.play(coorX, coorY); cout << reversi << endl; ++reversi; cout << reversi << endl; reversi.resizeTheBoard(4, 4); cout << "The board resizing to 4x4 board." << endl; reversi.printBoard(); reversi.getCoordinates(coorX, coorY); reversi.play(coorX, coorY); cout << reversi << endl; reversi++; cout << reversi << endl; }