private int minimax(int m, int dt, Board b, boolean max) {

        int bestValue;
        int val;

        if (dt == 0 || findPossibleMoves(max, b).length == 0) {

            return getRating(max, b, m);

        } else if (max == true) {

            bestValue = Integer.MIN_VALUE;

            for (int i : findPossibleMoves(true, b)) {

                Board nb = b;
                nb.move(max, m);

                val = minimax(i, dt - 1, nb, false);
                bestValue = Math.max(bestValue, val);

            }

            return bestValue;

        } else {

            bestValue = Integer.MAX_VALUE;

            for (int i : findPossibleMoves(false, b)) {

                Board nb = b;
                nb.move(max, m);

                val = minimax(i, dt - 1, nb, true);
                bestValue = Math.min(bestValue, val);

            }

            return bestValue;

        }

    }