i have a homework
my homework is to place the remaining 7 queens pieces from the game of chess
on a chessboard so that no queen piece is threatening another queen on the board after user had placed the 1st queen on the position of his choice.
I thought declaring an array like that int queen[8][8] and initially put 0 in entire array thenand put 1 for queen and put 2 to threatining place into this array.
I wrote this code:
But the problem is I can't back track to remove the queen if there's no place left for it to place in a particular row.Code:int a,b,check,queen[8][8],A,B,i,j;
for (i=0;a<=7;a++)
{
for (i=0;b<=7;b++)
{
queen[a][b]=0;
}
}
a=3; //suppose user input these co-ordinates
b=5;
queen[a][b]=1;
//loops for user placed queen
for (i=a+1;i<=7;i++) //to lock the corresponding lower column
queen[i][b]=2;
for (i=a-1;i>=0;i--) //to lock the corresponding upper column
queen[i][b]=2;
for (i=a-1,j=b+1;i>=0,j<=7;i--,j++) //to lock the corresponding upper right diagonal
queen[i][j]=2;
for (i=a-1,j=b-1;i>=0,j>=0;i--,j--) //to lock the corresponding upper left diagonal
queen[i][j]=2;
for (i=a+1,j=b+1;i<=7,j<=7;i++,j++) //to lock the corresponding lower right diagonal
queen[i][j]=2;
for (i=a+1,j=b-1;i<=7,j>=0;i++,j--) //to lock the corresponding lower left diagonal
queen[i][j]=2;
for (i=0;i<=7;i++)
{
for (j=0;j<=7;j++)
{
if (queen[i][j]==0)
{
queen[i][j]=1;
// and locked the corresponding column, rows, diagonals for this.
}
}
}
I tried to to this but it only increased the size of of my program and still no results.
Could someone please help me...???