Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int MAX_VALUE(int depth,boardState gameBoard,String typeOfHeurestic,int parentAlpha,int parentBeta){
- int currentAlpha = parentAlpha;
- int currentBeta = parentBeta;
- if(depth==TERMINAL_DEPTH){
- gameBoard.calculateHeuresticValue(currentPlayer,typeOfHeurestic);
- int retVal = gameBoard.getHeuresticValue();
- return retVal;
- }
- boolean endGame = endGameCondition(gameBoard);
- if(endGame){
- gameBoard.calculateHeuresticValue(currentPlayer,typeOfHeurestic);
- int retVal = gameBoard.getHeuresticValue();
- return retVal;
- }
- ArrayList<int[]> movesList = gameBoard.getSetOfValidMoves(currentPlayer);
- int v = Integer.MIN_VALUE;
- for(int i=0;i<movesList.size();i++){
- int[] element = movesList.get(i);
- boardState newBoard = new boardState(8,gameBoard.copyBoard());
- newBoard.placeCoin(element[0],element[1],currentPlayer);
- int valueRecursion = MIN_VALUE(depth+1,newBoard,typeOfHeurestic,currentAlpha,currentBeta);
- v= Integer.max(v,valueRecursion);
- if(v>=currentBeta)return v;
- currentAlpha = Integer.max(currentAlpha,v);
- }
- return v;
- }
- public static int MIN_VALUE(int depth,boardState gameBoard,String typeOfHeurestic,int parentAlpha,int parentBeta){
- int currentAlpha = parentAlpha;
- int currentBeta = parentBeta;
- if(depth==TERMINAL_DEPTH){
- gameBoard.calculateHeuresticValue(currentPlayer,typeOfHeurestic);
- int retVal = gameBoard.getHeuresticValue();
- return retVal;
- }
- boolean endGame = endGameCondition(gameBoard);
- if(endGame){
- gameBoard.calculateHeuresticValue(currentPlayer,typeOfHeurestic);
- int retVal = gameBoard.getHeuresticValue();
- return retVal;
- }
- ArrayList<int[]> movesList = gameBoard.getSetOfValidMoves(oppositePlayer);
- int v = Integer.MAX_VALUE;
- for(int i=0;i<movesList.size();i++){
- int[] element = movesList.get(i);
- boardState newBoard = new boardState(8,gameBoard.copyBoard());
- newBoard.placeCoin(element[0],element[1],oppositePlayer);
- int valueRecursion = MAX_VALUE(depth+1,newBoard,typeOfHeurestic,currentAlpha,currentBeta);
- v= Integer.min(v,valueRecursion);
- if(v<=currentAlpha)return v;
- currentBeta = Integer.min(currentBeta,v);
- }
- return v;
- }
- public static int[] miniMaxAlgorithm(int depth,boardState gameBoard,String typeOfHeurestic){
- int rootAlpha = Integer.MIN_VALUE;
- int rootBeta = Integer.MAX_VALUE;
- ArrayList<int[]> movesList = gameBoard.getSetOfValidMoves(currentPlayer);
- int v = Integer.MIN_VALUE;
- int bestMoveIndex = 0;
- for(int i=0;i<movesList.size();i++){
- int[] element = movesList.get(i);
- boardState newBoard = new boardState(8,gameBoard.copyBoard());
- newBoard.placeCoin(element[0],element[1],currentPlayer);
- int retVal = MIN_VALUE(depth+1,newBoard,typeOfHeurestic,rootAlpha,rootBeta);
- v = Integer.max(v,retVal);
- if(v>=rootAlpha){
- rootAlpha=v;
- bestMoveIndex=i;
- }
- }
- return movesList.get(bestMoveIndex);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement