Results 1 to 13 of 13
Thread: loop program
- 09-08-2011, 10:22 AM #1
Member
- Join Date
- Sep 2011
- Posts
- 6
- Rep Power
- 0
- 09-08-2011, 10:31 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: loop program
That method basically does this:
That isn't of much use is it? To speed your development up a bit, google for 'eight queens problem' because that's what you're trying to solve.Java Code:public static int testconstraints(char[][] board,int rowCheck, int colCheck) { // al whole lot of mumbo jumbo and finally: return 0; }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 09-08-2011, 11:52 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: 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 PM #4
Member
- Join Date
- Sep 2011
- Posts
- 6
- Rep Power
- 0
Re: 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 PM #5
Re: 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 PM #6
Member
- Join Date
- Sep 2011
- Posts
- 6
- Rep Power
- 0
Re: 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 PM #7
Re: 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,0Last edited by Norm; 09-08-2011 at 03:27 PM. Reason: Board is 8x8
- 09-08-2011, 02:17 PM #8
Member
- Join Date
- Sep 2011
- Posts
- 6
- Rep Power
- 0
Re: loop program
is this code somewhat correct?
it checks the rows and columns
sorry, if my question is silly...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 PM #9
Re: 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 PM #10
Member
- Join Date
- Sep 2011
- Posts
- 6
- Rep Power
- 0
Re: loop program
till now, I didn't get any idea for solving this problem.
I lost.........
- 09-08-2011, 03:08 PM #11
Member
- Join Date
- Sep 2011
- Posts
- 6
- Rep Power
- 0
Re: loop program
Hi Norm,
Can you give the code for this problem?
- 09-08-2011, 03:29 PM #12
Re: 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 AM #13
Re: loop program
Similar Threads
-
How to loop this program??
By 7auz in forum New To JavaReplies: 4Last Post: 01-01-2011, 03:08 AM -
Need help writing program to compare 2 strings using a loop
By kornwheat in forum New To JavaReplies: 15Last Post: 11-06-2009, 10:31 AM -
Loop Program Help Please?
By rjones215 in forum New To JavaReplies: 2Last Post: 10-07-2009, 10:50 PM -
Trouble with For loop and variables in a program
By dablyz in forum New To JavaReplies: 12Last Post: 05-06-2008, 04:25 AM -
Need another program with and if-else, array, and for loop
By Zebra in forum New To JavaReplies: 2Last Post: 05-05-2008, 01:56 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks