Hi,

I'm novoice to java. I'm trying a program for place 8 X’s on the board with 64 boxes(8*8 matrix) in such a way that:

Printable View

- 09-08-2011, 10:22 AMjavanovoiceloop program
Hi,

I'm novoice to java. I'm trying a program for place 8 X’s on the board with 64 boxes(8*8 matrix) in such a way that: - 09-08-2011, 10:31 AMJosAHRe: loop program
That method basically does this:

Code:`public static int testconstraints(char[][] board,int rowCheck, int colCheck) {`

// al whole lot of mumbo jumbo and finally:

return 0;

}

kind regards,

Jos - 09-08-2011, 11:52 AMTollsRe: loop program
Can I suggest you learn about indenting your code correctly?

That's painful to read at the moment.

At least you've got your naming mostly correct. - 09-08-2011, 01:43 PMjavanovoiceRe: loop program
Hi JosAH,

Thanks for your suggestion. But i couldn't understand that 8 queen program code.

Please help me to solve my program.. - 09-08-2011, 01:56 PMNormRe: loop program
The queen is the most powerful chess piece. The 8 queens problem is about how to place the queens on the board so none of them threaten another one.

To solve your problem you need a method that tests if a square is on the same row, column or diagonal of an occupied square. - 09-08-2011, 02:02 PMjavanovoiceRe: loop program
Can you please suggest any idea about the method to test the constraints?

I have been trying to find that trick for last two days..

Please help me sir... - 09-08-2011, 02:09 PMNormRe: loop program
Given a square's x,y

Compute all the squares on the same row (ie row = x)

Compute all the squares on the same col (ie col = y)

Compute all the squares on the upperleft-lowerrright diag (take a piece of paper and work it out

0,0 -> 1,1 -> 2,2 -> ... 7,7

Compute all the squares on the upperright-lowerleft diag (same idea as above)

0,7 -> 1,7 -> ... 7,0 - 09-08-2011, 02:17 PMjavanovoiceRe: loop program
is this code somewhat correct?

it checks the rows and columns

Quote:

if(board[rowCheck][0]=='X' || board[rowCheck][1]=='X' ||board[rowCheck][2]=='X' ||board[rowCheck][3]=='X' ||board[rowCheck][4]=='X' ||board[rowCheck][5]=='X' ||board[rowCheck][6]=='X' ||board[rowCheck][7]=='X' )

{

if(board[0][colCheck]=='X' || board[1][colCheck]=='X' || board[2][colCheck]=='X' || board[3][colCheck]=='X' || board[4][colCheck]=='X' || board[5][colCheck]=='X' || board[6][colCheck]=='X' || board[7][colCheck]=='X' )

{

actually, row and column is selected randomly and then checks for the constraints to place 'X' in that place... - 09-08-2011, 02:19 PMNormRe: loop program
Write a test program to compile and execute it and let the computer tell you if it is correct.

I might use a loop vs having the long conditions in the if statements - 09-08-2011, 02:57 PMjavanovoiceRe: loop program
till now, I didn't get any idea for solving this problem.

I lost......... - 09-08-2011, 03:08 PMjavanovoiceRe: loop program
Hi Norm,

Can you give the code for this problem? - 09-08-2011, 03:29 PMNormRe: loop program
Your code will work for the rows and columns, now you need to work out the algorithm for the diagonals.

I have never written code for this problem so I have nothing to give except some ideas.

Take a piece of paper and see how to vary the row and column values to go on each diagonal and how to detect when you are at the edge of the board. - 09-09-2011, 03:01 AMJunkyRe: loop program