# নাইটস ট্যুর

 0 1- The Knight can move in the shape of the letter, 'L', over two in one direction and then over one in a perpendicular direction. 2- If the Knight rests at the square marked X. 3- The board is represented by an 8-by-8 two-dimensional array. 4- The Knights can be placed on the board as specified above so that no two Knights are attacking each other. 5- the most important thing is to complete number 4 (according to the code(queen) below need to change for Knight ```public class Queens { int[] x; public Queens(int N) { x = new int[N]; } public boolean canPlaceQueen(int r, int c) { /* Returns TRUE if a queen can be placed in row r and column c. Otherwise it returns FALSE. x[] is a global array whose first (r-1) values have been set. */ for (int i = 0; i < r; i++) { if (x[i] == c || (i - r) == (x[i] - c) ||(i - r) == (c - x[i])) { return false; } } return true; } public void printQueens(int[] x) { int N = x.length; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (x[i]==j) { System.out.print("Q "); } else { System.out.print("* "); } } System.out.println(); } System.out.println(); } /* public void placeNqueens(int r, int n) { //Using backtracking this method prints all possible placements of n //queens on an n x n chessboard so that they are non-attacking. for (int c = 0; c < n; c++) { if (canPlaceQueen(r, c)) { x[r] = c; if (r == n-2 && c==n-1 || r==n-1 && c==n-2 ) { printQueens(x); } else { placeNqueens(r+1, n); } } } } */ public void placeNqueens(int r, int n) { /* Using backtracking this method prints all possible placements of n queens on an n x n chessboard so that they are non-attacking. */ for (int c = 0; c < n; c++) { if (canPlaceQueen(r, c)) { x[r] = c; if (r == n-1) { printQueens(x); } else { placeNqueens(r+1, n); } } } } public void callplaceNqueens() { placeNqueens(0, x.length); } public static void main(String args[]) { Queens Q = new Queens(8); Q.callplaceNqueens(); } } ``` asked 04 Nov '17, 18:04 hunted 11●1
Be the first one to answer this question!
 toggle preview community wiki:

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Question tags:

×215
×1

question asked: 04 Nov '17, 18:04

question was seen: 677 times

last updated: 04 Nov '17, 18:43