private int alphabeta(int m, int dt, int a, int b, Board B, boolean max) {

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

            return getRating(max, B, m);

        } else if (max == true) {

            for (int i : findPossibleMoves(max, B)) {

                Board nB = B;
                nB.move(max, m);

                a = Math.max(a, alphabeta(i, dt - 1, a, b, nB, false));

                if (b <= a) {

                    break;

                }

            }

            return a;

        } else {

            for (int i : findPossibleMoves(max, B)) {

                Board nB = B;
                nB.move(max, m);

                b = Math.min(b, alphabeta(i, dt - 1, a, b, nB, true));

                if (b <= a) {

                    break;

                }

            }

            return b;

        }

    }