public projectedGainForSpace getBestSpaceForOneMoveAlphaBetaMin( board currentBoard, projectedGainForSpace min, projectedGainForSpace max, String playerName) { List<space> availableSpaces = currentBoard.getAvailableSpaces(playerName); if (availableSpaces.isEmpty()) return new projectedGainForSpace(0, null); int bestPoints = max.gain; space bestSpace = availableSpaces.get(0); for (int index = 0; index < availableSpaces.size(); index++) { space currentSpace = availableSpaces.get(index); int row = currentSpace.row; int column = currentSpace.column; int pointsGained = currentSpace.value; if (currentBoard.isSpaceDeathBlizable(currentSpace.row, currentSpace.column, playerName)) pointsGained += currentBoard.getPointsGainedFromBlitz(row, column, playerName); if (pointsGained < bestPoints) { bestPoints = pointsGained; bestSpace = currentSpace; } if (pointsGained < min.gain) { return min; } } max.gain = bestPoints; max.nextSpace = bestSpace; projectedGainForSpace bestSpaceGain = new projectedGainForSpace(bestPoints, bestSpace); return bestSpaceGain; }
public projectedGainForSpace getAlphaBetaBestSpace( board currentBoard, int turns, projectedGainForSpace min, projectedGainForSpace max, String playerName) { if (turns == 0) return getBestSpaceForOneMove(currentBoard, playerName); // if(currentBoard.availableSpaces==1) return getBestSpaceForOneMove(currentBoard, this.name); int bestGain; if (playerName == this.name) { bestGain = -50000; } else { bestGain = 50000; } List<space> availableSpaces = currentBoard.getAvailableSpaces(playerName); if (availableSpaces.isEmpty()) return new projectedGainForSpace(0, null); space bestSpace = availableSpaces.get(0); for (int index = 0; index < availableSpaces.size(); index++) { space currentSpace = availableSpaces.get(index); // System.out.println("min is " + min.gain +", max is " + max.gain); int projectedGain = findProjectedGainAlphaBeta(currentSpace, currentBoard, turns, min, max, playerName); if (playerName == this.name) { if (projectedGain > bestGain) { bestGain = projectedGain; bestSpace = currentSpace; } } else { if (projectedGain < bestGain) { bestGain = projectedGain; bestSpace = currentSpace; } } } projectedGainForSpace bestSpaceGain = new projectedGainForSpace(bestGain, bestSpace); return bestSpaceGain; }
public projectedGainForSpace getMiniMaxBestSpace(board currentBoard, int turns) { if (turns == 0) return getBestSpaceForOneMove(currentBoard, this.name); // if(currentBoard.availableSpaces==1) return getBestSpaceForOneMove(currentBoard, this.name); int bestGain = -50000; List<space> availableSpaces = currentBoard.getAvailableSpaces(this.name); if (availableSpaces.isEmpty()) return new projectedGainForSpace(0, null); space bestSpace = availableSpaces.get(0); for (int index = 0; index < availableSpaces.size(); index++) { space currentSpace = availableSpaces.get(index); int projectedGain = findProjectedGain(currentSpace, currentBoard, turns); if (projectedGain > bestGain) { bestGain = projectedGain; bestSpace = currentSpace; } this.totalNodesExamined++; } projectedGainForSpace bestSpaceGain = new projectedGainForSpace(bestGain, bestSpace); return bestSpaceGain; }