Computing.Net > Forums > Programming > 8 queens

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

8 queens

Reply to Message Icon

Name: Rich
Date: August 3, 2003 at 17:01:39 Pacific
OS: 2000k
CPU/Ram: PIII500
Comment:

I'm sorry for posting homework, but I can't figure out why this thing isn't running right. Could someone please take a look at this and see what I did wrong? THANKS!

#include

int row, col, count=0;
int CheckBoard(int row, int col);
int board[8][8]={0};

main()
{
int PlaceQueen=0;

do
{
col=0;

//loop to check the board
do
{
printf("%d %d\n", row, col);
if(CheckBoard(row, col)==1)
board[row][col]=3;
else col++;

//clears the column in column is over 8 and removes queen from counter
if(col>8){
row--;
for(col=0; col0);

//checks diag #3 (--)
printf("diag3\n");}
if(x!=7){
r=row;
c=col;
do
{
if(board[r][c]!=3){
c--;
r--;}
else
x=7;
}while(x!=7&&c>0&&r>0);

//checks diag #4 (-+)
printf("diag4\n");}
if(x!=7){
r=row;
c=col;
do
{
if(board[r][c]!=3){
c--;
r++;}
else
x=7;
}while(x!=7&&c>0&&r>0);}

printf("%d %d\n", row, col);

//returns 1 if no queen attack, 0 if queen attack
if(x!=7)
return 1;
else
return 0;
}



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: August 3, 2003 at 19:40:55 Pacific
Reply:

I don't think that anyone has a problem with homework posting if you have attempted to write some code and are asking for help. It's the people that want it all done for them that get ignored/flamed.

I very recently heard about the "8 queens" problem, otherwise I wouldn't know what you are trying to do. A little description of what you want to do and what is happening would be helpful.


0

Response Number 2
Name: Rich
Date: August 3, 2003 at 20:20:59 Pacific
Reply:

Good point.

The 8 queens problem is to take a regular 8x8 checker board and place 8 queens on it so that no queen can attack any other queen using standard chess moves.

You will notice alot of superfulous printf statements in this code, I put them in to tell me where the program made it to so that I could hopefully figure out where it went wrong. It didn't help.

I'm sure that its something little that I overlooked, but I've been staring at it for too long and can't see it. Thats why I'm hoping that you guys here will be able to help.

Thanks.


0

Response Number 3
Name: Rich
Date: August 4, 2003 at 20:32:27 Pacific
Reply:

I have once again changed it and wanted to see if anyone was out there that could help me understand this thing. The assignment is already turned in, so I just want to see where my mistake was and have a working program for future reference. The include is . Thanks.

#include

int row, col, x=0;
int c, r, count;
int board[8][8]={0};
int PlaceQueen=0;


main()
{
do
{
c=0;
do
{
//checks horizontal (-)
printf("horizontal\n");
do
{
if(board[row][c]!=3)
c++;
else
x=7;
}while(c0);
printf("r=%d, c=%d, x=%d\n", r, c, x);

//checks diag #3 (--)
printf("diag3\n");}
if(x!=7){
r=row;
c=col;
do
{
if(board[r][c]!=3){
c--;
r--;}
else
x=7;
}while(c>0&&r>0);
printf("r=%d, c=%d, x=%d\n", r, c, x);

//checks diag #4 (-+)
printf("diag4\n");}
if(x!=7){
r=row;
c=col;
do
{
if(board[r][c]!=3){
c--;
r++;}
else
x=7;
}while(c>0&&r8){
row--;
for(col=0; col8;col++){
board[row][col]=0;}
col=0;
PlaceQueen--;
printf("place queen minus=%d\n",PlaceQueen);}

}while(board[row][col]==0);

printf("Made it farther\n");
PlaceQueen++;
printf("place queen=%d\n",PlaceQueen);
row++;
printf("%d %d\n", row, col);
}while(PlaceQueen8);

//prints out answer
count=1;
for(row=0; row8; row++){
for(col=0; col8; col++){
if(board[row][col]!=0){
printf("%d ",count);
count++;}
}
}
return 0;
}


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Highly anynomous proxies help in movie booking sys...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: 8 queens

Chess Challange www.computing.net/answers/programming/chess-challange/5127.html

Hex code? www.computing.net/answers/programming/hex-code/7793.html

8-bit to 16-bit Waveform Audio www.computing.net/answers/programming/8bit-to-16bit-waveform-audio/4418.html