Ejemplo n.º 1
0
  private Move getMinMaxBestMove(Board board, List<Move> moves) {
    int size = board.getBoardSize();
    int maxScore = 0;
    Move myBestMove = moves.get(0);
    for (int k = 0; k < moves.size(); k++) {
      Move myMove = moves.get(k);
      int minScore = Integer.MAX_VALUE;
      for (int i = interval; i < size; i += interval) {
        for (int j = interval; j < size; j += interval) {
          Move othersMove = Move.createOthersMove(1, i, j);
          int thisScore = testMyScoreWithThisMove(board, myMove, othersMove);
          if (thisScore < minScore) {
            minScore = thisScore;
          }
        }
      }

      if (minScore > maxScore) {
        maxScore = minScore;
        myBestMove = myMove;
      }
    }

    return myBestMove;
  }
Ejemplo n.º 2
0
 private void addSampleMoves(Board board) {
   int size = board.getBoardSize();
   for (int i = interval; i < size; i += interval) {
     for (int j = interval; j < size; j += interval) {
       sampleMoves.add(Move.createMyMove(i, j));
     }
   }
 }
Ejemplo n.º 3
0
  @Override
  public Move makeAMove(Board board) {
    if (sampleMoves.size() == 0) {
      addSampleMoves(board);
    }

    if (board.getPrevMoves().size() == 0) {
      firstPlayer = true;
      return Move.createMyMove(board.getBoardSize() / 2, board.getBoardSize() / 2);
    }

    if (firstPlayer) {
      Move myMove = getMinMaxBestMove(board, sampleMoves);
      Move bestMove = getBestRandomMove(board, myMove.x - 50, myMove.y - 50, 100);
      return bestMove;
    } else {
      return getBestOnePixelOffMove(board);
    }
  }
Ejemplo n.º 4
0
 private boolean isValidMove(Board board, int x, int y) {
   if (x < 0
       || y < 0
       || x >= board.getBoardSize()
       || y >= board.getBoardSize()
       || !board.isEmptyAt(x, y)) {
     return false;
   }
   return true;
 }
Ejemplo n.º 5
0
  public int testMyScoreWithThisMove(Board board, Move myMove, Move othersMove) {

    double[][][] currPull = board.getCurrPull();
    int size = board.getBoardSize();

    int myScore = 0;
    for (int i = 0; i < size; i++) {
      for (int j = 0; j < size; j++) {
        double newMyPull = currPull[i][j][0] + 1 / AbsPlayer.getDistanceSq(i, j, myMove);
        double newOthersPull = currPull[i][j][1] + 1 / AbsPlayer.getDistanceSq(i, j, othersMove);
        if (newMyPull > newOthersPull) {
          myScore++;
        } else {
          myScore--;
        }
      }
    }

    return myScore;
  }