public Pair play(State game) { int bestValue = Integer.MIN_VALUE; Pair bestMove = null; for(Pair move : game.getMove(game.getCurrentPlayer())) { State nextState = game.play(move); complexity++; int value = -alphabeta(nextState, this.depth,Integer.MIN_VALUE,Integer.MAX_VALUE); if (value > bestValue) { bestValue = value; bestMove = move; } } return bestMove; } private int alphabeta(State state, int depth,int alpha,int beta) { if(depth == 0 || state.isOver()) { return evaluate(state); } else { for (Pair move : state.getMove(state.getCurrentPlayer())) { State nextState = state.play(move); alpha = Math.max(alpha,-alphabeta(nextState,depth-1,-beta,-alpha)); if(alpha >= beta) return alpha; } return alpha; } }