Ejemplo n.º 1
0
  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;
  }