package nl.ap.hillclimbing;

public class Queens {

    public static boolean isConsistent(int[] q, int n) {
        for (int i = 0; i < n; i++) {
            if (q[i] == q[n]) {
                return false; // same column
            }

            if ((q[i] - q[n]) == (n - i)) {
                return false; // same major diagonal
            }

            if ((q[n] - q[i]) == (n - i)) {
                return false; // same minor diagonal
            }
        }

        return true;
    }

    public static void printQueens(int[] q) {
        int N = q.length;

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (q[i] == j) {
                    System.out.print("Q  ");
                } else {
                    System.out.print("*  ");
                }
            }

            System.out.println();
        }

        System.out.println();
    }

    public static void calculate(int N) {
        int[] a = new int[N];

        calculate(a, 0);
    }

    public static boolean calculate(int[] q, int n) {
        int N = q.length;

        if (n == N) {
            printQueens(q);

            return true;
        } else {
            for (int i = 0; i < N; i++) {
                q[n] = i;

                if (isConsistent(q, n)) {
                    if (calculate(q, n + 1)) {
                        return true;
                    }
                }
            }
        }

        return false;
    }


    public static void main(String[] args) {
//        calculate(new int[]{0, 0, 0, 0, 0, 0, 0, 0}, 0);
//
//        calculate(new int[]{5, 0, 0, 0, 0, 0, 0, 0}, 1);
//
//        calculate(new int[]{5, 3, 0, 0, 0, 0, 0, 0}, 2);
//
//        calculate(new int[]{5, 3, 0, 0, 0, 0, 0, 0, 5, 3, 0, 0, 0, 0, 0, 0}, 0);
//
//        calculate(new int[]{5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0);
//
//        calculate(new int[]{0, 0, 0, 0, 0, 0}, 0);
//
//        calculate(new int[]{0, 0, 0, 0}, 0);
//
//        calculate(new int[]{0}, 0);

        calculate(1);

        calculate(8);
    }

}

@@ -83,39 +83,49 @@
 nsistent(int%5B%5D q
+ueens
 , int n
+umber
 ) %7B%0A        for 
@@ -141,16 +141,21 @@
 0; i %3C n
+umber
 ; i++) %7B
@@ -176,16 +176,21 @@
 f (q
+ueens
 %5Bi%5D == q
 %5Bn%5D)
@@ -185,18 +185,28 @@
 %5Bi%5D == q
-%5Bn
+ueens%5Bnumber
 %5D) %7B%0A   
@@ -284,25 +284,40 @@
  ((q
+ueens
 %5Bi%5D - q
-%5Bn
+ueens%5Bnumber
 %5D) == (n
  - i
@@ -304,32 +304,37 @@
 s%5Bnumber%5D) == (n
+umber
  - i)) %7B%0A       
@@ -416,15 +416,30 @@
  ((q
-%5Bn%5D - q
+ueens%5Bnumber%5D - queens
 %5Bi%5D)
@@ -444,16 +444,21 @@
 %5D) == (n
+umber
  - i)) %7B
@@ -614,33 +614,38 @@
 ) %7B%0A        int 
-N
+length
  = q.length;%0A%0A  
@@ -662,33 +662,38 @@
 (int i = 0; i %3C 
-N
+length
 ; i++) %7B%0A       
@@ -717,17 +717,22 @@
  0; j %3C 
-N
+length
 ; j++) %7B
@@ -1032,17 +1032,22 @@
 ate(int 
-N
+length
 ) %7B%0A    
@@ -1068,17 +1068,22 @@
 new int%5B
-N
+length
 %5D;%0A%0A    
@@ -1153,23 +1153,33 @@
 (int%5B%5D q
+ueens
 , int n
+umber
 ) %7B%0A    
@@ -1190,13 +1190,23 @@
 int 
-N = q
+length = queens
 .len
@@ -1228,13 +1228,23 @@
 f (n
- == N
+umber == length
 ) %7B%0A
@@ -1268,16 +1268,21 @@
 Queens(q
+ueens
 );%0A%0A    
@@ -1355,9 +1355,14 @@
 i %3C 
-N
+length
 ; i+
@@ -1383,18 +1383,28 @@
        q
-%5Bn
+ueens%5Bnumber
 %5D = i;%0A%0A
@@ -1437,19 +1437,29 @@
 istent(q
-, n
+ueens, number
 )) %7B%0A   
@@ -1490,19 +1490,29 @@
 culate(q
-, n
+ueens, number
  + 1)) %7B

Rename some stuff