8 Bishops to occupy whole board [Backtracking]
<p>I have a task to write a program which sets up 8 bishops in chess board to occupy whole board. It should end up when first solution is found and print everything out. Here's my written code in Java, and I struggle with finishing it using backtracking ( that place is commented in the code).</p>

<pre><code>/*
 * 0 - not occupied square
 * 1 - bishop standing square
 * 2 - occupied square (diagonal)
 */
public class BishopsBT {
public int [][] solution;
final int N = 8; // number of squares in column and row (chess board)
final int solved = 120; //Sum of 1's and 2's in case of all occupied board
int sum; //current sum of board

public BishopsBT(){
    solution = new int [N][N] ;
}

public void solve() {
    if(placeBishops(0)){
        //print the result
        clear(); // clears all 2's
        for (int i = 0; i &lt; N; i++) {
            for (int j = 0; j &lt; N; j++) {
                System.out.print(" " + solution[i][j]);
            }
            System.out.println();
        }
    } else{
        System.out.println("NO SOLUTION EXISTS");
    }
}

public boolean placeBishops (int bishop){

    for (int row = 0; row &lt; N; row++) {
        // check if bishop can be placed
        if (canPlace(solution, row, bishop)) {
            // place the bishop
            solution[row][bishop] = 1;  
            }
        }

    if (allSpaceOccupied()) {
        return true;
    } else {
        // SOME BACKTRACKING CODE HERE
        return false;
    }

    }

// check if bishop can be placed at matrix[row][column]
public boolean canPlace(int[][] matrix, int row, int column) {

    // we need to check all diagonals
    // whether no bishop is standing there

    for (int i = row, j = column; i &gt;= 0 &amp;&amp; j &gt;= 0; i--, j--) {
        if (matrix[i][j] == 1) {
            return false;
        }
    }

    for (int i = row, j = column; i &gt;= 0 &amp;&amp; j &lt; matrix.length; i--, j++) {
        if (matrix[i][j] == 1) {
            return false;
        }
    }

    for (int i = row, j = column; i &lt; matrix.length &amp;&amp; j &gt;= 0; i++, j--) {
        if (matrix[i][j] == 1) {
            return false;
        }
    }

    for (int i = row, j = column; i &lt; matrix.length &amp;&amp; j &lt; matrix.length; i++, j++) {
        if (matrix[i][j] == 1) {
            return false;
        }
    }
    // if we are here that means we are safe to place Bishop
    return true;
}

public boolean allSpaceOccupied() {

    // clears previously occupied space
    clear();

    // occupies new space
    for (int i = 0; i &lt; solution.length; i++) {
        for ( int j = 0; j &lt; solution.length; j++) {
    if (solution[i][j] == 1) diagonalOccupy(i,j);
        }
    }
    sum = 0;
    // counts sum of occupied space
    for (int i = 0; i &lt; solution.length; i++) {
        for ( int j = 0; j &lt; solution.length; j++) {
    sum += solution [i][j];
        }
    }

    if (sum == solved) return true;
    // else
    return false;
}

public void diagonalOccupy(int row, int column) {
    // writes 2 in each bishop's occupied square
    for (int i = row, j = column; i &gt;= 0 &amp;&amp; j &gt;= 0; i--, j--) {
        if (solution[i][j] == 0) {
            solution[i][j] = 2;
        }
    }

    for (int i = row, j = column; i &gt;= 0 &amp;&amp; j &lt; solution.length; i--, j++) {
        if (solution[i][j] == 0) {
            solution[i][j] = 2;
        }
    }

    for (int i = row, j = column; i &lt; solution.length &amp;&amp; j &gt;= 0; i++, j--) {
        if (solution[i][j] == 0) {
            solution[i][j] = 2;
        }
    }

    for (int i = row, j = column; i &lt; solution.length &amp;&amp; j &lt; solution.length; i++, j++) {
        if (solution[i][j] == 0) {
            solution[i][j] = 2;
        }
    }

}
 // clears all 2's on the board
public void clear() {
    for (int i = 0; i &lt; solution.length; i++) {
        for ( int j = 0; j &lt; solution.length; j++) {
            if (solution[i][j] == 2) solution[i][j] = 0;
        }
    }
}

public static void main(String[] args) {
    BishopsBT q = new BishopsBT();
    q.solve();
}
}
</code></pre>

<p>The thing is that at the moment my program puts bishops in first column and this layout does not occupy all space. Of course, I could simply put everything in third column and problem is solved. However, I have to use backtracking and have no idea how. If you have any ideas or tips, I would be really glad to hear them.</p>