Hi ,help needed in bishop movement c++..the code is woking fine giving desired output most of time but there is one thing unintentional happening in the algorithm..
to understand the problem plz see the diagram (ignore the 'oo' and 'o' and consider them double and single spaces respectively, they are just to keep diagram structure intact otherwise more than one spaces dont show up in forums)
oo|oo|oo|oA
------------------
oo|oo|oA|oB
------------------
oo|o◘|oo|oo
------------------
oo|oo|oo|oo
the black square(◘) is bishop ..according to chess rule it can move to location of either of the As..in my case it is perfeclty moving to A but problem is that it is also moving towards B which i dont want
below is the code of primary diagonal ...sr stands for source row ,sc for source column ,dr for destination row and dc for destination column
bool validBishop(char board[][8],int inputs[])
{
int sr=inputs[0] , sc=inputs[1] , dr=inputs[2] , dc=inputs[3];
bool ok= false;
if(sr>dr && sc<dc)
{
for( int i=sr-1, j=sc+1; i>=h,j<=k; )
{
if(board[i][j] == ' ')
{
ok1=true;
i--;
j++;
}
else
{
ok=false;
break;
}
}
if(ok==true)
{
return true;
}else
{
return false;
}
}
}