Exemplo n.º 1
0
  private Move getBestOnePixelOffMove(Board board) {
    List<Move> otherPlayersMove = board.getPrevMovesByPlayerId(1);
    double maxScore = 0;
    Move bestMove = null;

    for (int j = 0; j < otherPlayersMove.size(); j++) {
      Move prevMove = otherPlayersMove.get(j);
      for (int i = 0; i < directions.length; i++) {
        int nextX = prevMove.x + directions[i][0];
        int nextY = prevMove.y + directions[i][1];
        if (isValidMove(board, nextX, nextY)) {
          Move thisMove = Move.createMyMove(nextX, nextY);
          double thisScore = board.testMyScoreWithThisMove(thisMove);
          if (thisScore > maxScore) {
            maxScore = thisScore;
            bestMove = thisMove;
          }
        } else {
          int nextX2 = prevMove.x + directions[i][0] * 2;
          int nextY2 = prevMove.y + directions[i][1] * 2;
          if (isValidMove(board, nextX2, nextY2)) {
            Move thisMove = Move.createMyMove(nextX2, nextY2);
            double thisScore = board.testMyScoreWithThisMove(thisMove);
            if (thisScore > maxScore) {
              maxScore = thisScore;
              bestMove = thisMove;
            }
          }
        }
      }
    }
    return bestMove;
  }