///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%lld",&a)
#define sf2(a,b) scanf("%lld %lld",&a,&b)
#define sf3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf(a) printf("%lld",a)
#define pf2(a,b) printf("%lld %lld",a,b)
#define pf3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define timesave ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
//const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
//const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
char board[8][9];
int check(int wi, int wj,int bi, int bj)
{
int i,j;
i=wi;
j=wj;
//queen and rook
while (--j>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='r')
return 1;
else
break;
}
j=wj;
//queen and rook
while (++j<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='r')
return 1;
else
break;
}
j=wj;
//queen and rook
while (--i>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='r')
return 1;
else
break;
}
i=wi;
//queen and rook
while (++i<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='r')
return 1;
else
break;
}
i=wi;
//queen and bishop
while (--j>=0 && --i>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='b')
return 1;
else
break;
}
i=wi;
j=wj;
//queen and bishop
while (--j>=0 && ++i<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='b')
return 1;
else
break;
}
i=wi;
j=wj;
//queen and bishop
while (++j<8 && --i>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='b')
return 1;
else
break;
}
i=wi;
j=wj;
//queen and bishop
while (++j<8 && ++i<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='b')
return 1;
else
break;
}
i=wi-1;
j=wj;
//pawn check
if (i>=0)
{
if (j-1>=0 && board[i][j-1]=='p')
return 1;
if (j+1<8 && board[i][j+1]=='p')
return 1;
}
i++;
//knight check
if (i-2>=0)
{
if (j-1>=0 && board[i-2][j-1]=='n')
return 1;
if (j+1<8 && board[i-2][j+1]=='n')
return 1;
}
//knight check
if (i+2<8)
{
if (j-1>=0 && board[i+2][j-1]=='n')
return 1;
if (j+1<8 && board[i+2][j+1]=='n')
return 1;
}
//knight check
if (j-2>=0)
{
if (i-1>=0 && board[i-1][j-2]=='n')
return 1;
if (i+1<8 && board[i+1][j-2]=='n')
return 1;
}
//knight check
if (j+2<8)
{
if (i-1>=0 && board[i-1][j+2]=='n')
return 1;
if (i+1<8 && board[i+1][j+2]=='n')
return 1;
}
// black king check checking
i=bi;
j=bj;
while (--j>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='R')
return 2;
else
break;
}
j=bj;
while (++j<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='R')
return 2;
else
break;
}
j=bj;
while (--i>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='R')
return 2;
else
break;
}
i=bi;
while (++i<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='R')
return 2;
else
break;
}
i=bi;
while (--j>=0 && --i>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='B')
return 2;
else
break;
}
i=bi;
j=bj;
while (--j>=0 && ++i<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='B')
return 2;
else
break;
}
i=bi;
j=bj;
while (++j<8 && --i>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='B')
return 2;
else
break;
}
i=bi;
j=bj;
while (++j<8 && ++i<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='B')
return 2;
else
break;
}
i=bi+1;
j=bj;
if (i<8)
{
if (j-1>=0 && board[i][j-1]=='P')
return 2;
if (j+1<8 && board[i][j+1]=='P')
return 2;
}
i--;
if (i-2>=0)
{
if (j-1>=0 && board[i-2][j-1]=='N')
return 2;
if (j+1<8 && board[i-2][j+1]=='N')
return 2;
}
if (i+2<8)
{
if (j-1>=0 && board[i+2][j-1]=='N')
return 2;
if (j+1<8 && board[i+2][j+1]=='N')
return 2;
}
if (j-2>=0)
{
if (i-1>=0 && board[i-1][j-2]=='N')
return 2;
if (i+1<8 && board[i+1][j-2]=='N')
return 2;
}
if (j+2<8)
{
if (i-1>=0 && board[i-1][j+2]=='N')
return 2;
if (i+1<8 && board[i+1][j+2]=='N')
return 2;
}
return 0;
}
int main()
{
int test=1;
while (1)
{
for (int i=0; i<8; i++)
scanf("%s",board[i]);
int wi,wj,bi,bj,blank=0;
for (int i=0; i<8; i++)
for (int j=0; j<8; j++)
{
if (board[i][j]=='.')
blank++;
else if (board[i][j]=='K')
{
wi=i;
wj=j;
}
else if (board[i][j]=='k')
{
bi=i;
bj=j;
}
}
if (blank==64)
break;
int c=check(wi,wj,bi,bj);
if (c==1)
printf("Game #%d: white king is in check.\n",test++);
else if (c==2)
printf("Game #%d: black king is in check.\n",test++);
else
printf("Game #%d: no king is in check.\n",test++);
}
return 0;
}
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%lld",&a)
#define sf2(a,b) scanf("%lld %lld",&a,&b)
#define sf3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf(a) printf("%lld",a)
#define pf2(a,b) printf("%lld %lld",a,b)
#define pf3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define timesave ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
//const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
//const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
char board[8][9];
int check(int wi, int wj,int bi, int bj)
{
int i,j;
i=wi;
j=wj;
//queen and rook
while (--j>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='r')
return 1;
else
break;
}
j=wj;
//queen and rook
while (++j<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='r')
return 1;
else
break;
}
j=wj;
//queen and rook
while (--i>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='r')
return 1;
else
break;
}
i=wi;
//queen and rook
while (++i<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='r')
return 1;
else
break;
}
i=wi;
//queen and bishop
while (--j>=0 && --i>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='b')
return 1;
else
break;
}
i=wi;
j=wj;
//queen and bishop
while (--j>=0 && ++i<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='b')
return 1;
else
break;
}
i=wi;
j=wj;
//queen and bishop
while (++j<8 && --i>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='b')
return 1;
else
break;
}
i=wi;
j=wj;
//queen and bishop
while (++j<8 && ++i<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='q' || board[i][j]=='b')
return 1;
else
break;
}
i=wi-1;
j=wj;
//pawn check
if (i>=0)
{
if (j-1>=0 && board[i][j-1]=='p')
return 1;
if (j+1<8 && board[i][j+1]=='p')
return 1;
}
i++;
//knight check
if (i-2>=0)
{
if (j-1>=0 && board[i-2][j-1]=='n')
return 1;
if (j+1<8 && board[i-2][j+1]=='n')
return 1;
}
//knight check
if (i+2<8)
{
if (j-1>=0 && board[i+2][j-1]=='n')
return 1;
if (j+1<8 && board[i+2][j+1]=='n')
return 1;
}
//knight check
if (j-2>=0)
{
if (i-1>=0 && board[i-1][j-2]=='n')
return 1;
if (i+1<8 && board[i+1][j-2]=='n')
return 1;
}
//knight check
if (j+2<8)
{
if (i-1>=0 && board[i-1][j+2]=='n')
return 1;
if (i+1<8 && board[i+1][j+2]=='n')
return 1;
}
// black king check checking
i=bi;
j=bj;
while (--j>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='R')
return 2;
else
break;
}
j=bj;
while (++j<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='R')
return 2;
else
break;
}
j=bj;
while (--i>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='R')
return 2;
else
break;
}
i=bi;
while (++i<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='R')
return 2;
else
break;
}
i=bi;
while (--j>=0 && --i>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='B')
return 2;
else
break;
}
i=bi;
j=bj;
while (--j>=0 && ++i<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='B')
return 2;
else
break;
}
i=bi;
j=bj;
while (++j<8 && --i>=0)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='B')
return 2;
else
break;
}
i=bi;
j=bj;
while (++j<8 && ++i<8)
{
if (board[i][j]=='.')
continue;
if (board[i][j]=='Q' || board[i][j]=='B')
return 2;
else
break;
}
i=bi+1;
j=bj;
if (i<8)
{
if (j-1>=0 && board[i][j-1]=='P')
return 2;
if (j+1<8 && board[i][j+1]=='P')
return 2;
}
i--;
if (i-2>=0)
{
if (j-1>=0 && board[i-2][j-1]=='N')
return 2;
if (j+1<8 && board[i-2][j+1]=='N')
return 2;
}
if (i+2<8)
{
if (j-1>=0 && board[i+2][j-1]=='N')
return 2;
if (j+1<8 && board[i+2][j+1]=='N')
return 2;
}
if (j-2>=0)
{
if (i-1>=0 && board[i-1][j-2]=='N')
return 2;
if (i+1<8 && board[i+1][j-2]=='N')
return 2;
}
if (j+2<8)
{
if (i-1>=0 && board[i-1][j+2]=='N')
return 2;
if (i+1<8 && board[i+1][j+2]=='N')
return 2;
}
return 0;
}
int main()
{
int test=1;
while (1)
{
for (int i=0; i<8; i++)
scanf("%s",board[i]);
int wi,wj,bi,bj,blank=0;
for (int i=0; i<8; i++)
for (int j=0; j<8; j++)
{
if (board[i][j]=='.')
blank++;
else if (board[i][j]=='K')
{
wi=i;
wj=j;
}
else if (board[i][j]=='k')
{
bi=i;
bj=j;
}
}
if (blank==64)
break;
int c=check(wi,wj,bi,bj);
if (c==1)
printf("Game #%d: white king is in check.\n",test++);
else if (c==2)
printf("Game #%d: black king is in check.\n",test++);
else
printf("Game #%d: no king is in check.\n",test++);
}
return 0;
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন