private int minmax(Color p, Board b, int d, int cutoff,
                       ArrayList<Integer> moves) {
        if (moves == null) {
            moves = new ArrayList<Integer>();
        }
        moves.clear();
        if (d <= 0) {
            return staticEval(p, b);
        } else {
            int maxsofar = Integer.MIN_VALUE + 10;
            for (int i = 0; i < b.size() * b.size(); i++) {
                if (b.isLegal(p, i)) {
                    int value;
                    b.addSpot(p, i);
                    if (b.getWinner() != null) {
                        value = Integer.MAX_VALUE;
                    } else {
                        value = -minmax(p.opposite(), b, d - 1,
                                -maxsofar, null);
                    }
                    b.undo();
                    if (value > cutoff) {
                        moves.clear();
                        return value;
                    }
                    if (value > maxsofar) {
                        moves.clear();
                    }
                    if (value >= maxsofar) {
                        moves.add(i);
                        maxsofar = value;
                    }
                }
            }
            return maxsofar;
        }
    }