Not so long ago I learned how to implement the minimax algorithm with alpha beta pruning, and even created a perfect Tic Tac Toe player. How can I improve this?
public Best chooseMove(boolean side,int[]board,int alpha,int beta,int depth,int maxDepth){
Best myBest = new Best();
Best reply;
int num;
if(Board.checkGameOver(board)||depth==maxDepth){
Best fakeBest = new Best();
fakeBest.setScore(returnPositionScore(board));
return fakeBest;
}
if(side){
myBest.setScore(alpha);
num = numberOfEngine;
}
else{
myBest.setScore(beta);
num = numberOfOpponent;
}
ArrayList<Integer> availableMoves = new ArrayList<Integer>(searchAvailableMoves(board));
for(Integer move:availableMoves){
board[move.intValue()] = num;
reply = chooseMove(!side,board,alpha,beta,depth+1,maxDepth);
board[move.intValue()] = 0;
if(side&&reply.getScore()>myBest.getScore()){
myBest.setMove(move.intValue());
myBest.setScore(reply.getScore());
alpha = reply.getScore();
}
else if(!side&&reply.getScore()<myBest.getScore()){
myBest.setMove(move.intValue());
myBest.setScore(reply.getScore());
beta = reply.getScore();
}
if(alpha>=beta){
return myBest;
}
}
return myBest;
}