Advertisement
Guest User

yanded warmup A

a guest
May 16th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. int main()
  4. {
  5.       int wkx, wky, wrx, wry, bkx, bky;
  6.       char s[10];
  7.       gets(s);
  8.       wkx = s[0] - 97;
  9.       wky = s[1] - 49;
  10.       wrx = s[3] - 97;
  11.       wry = s[4] - 49;
  12.       bkx = s[6] - 97;
  13.       bky = s[7] - 49;
  14.  
  15.       int kingattack[8][8] = {0};
  16.       int rookattack[8][8] = {0};
  17.  
  18.       for (int dx = -1; dx <= 1; dx++)
  19.             for (int dy = -1; dy <= 1; dy++)
  20.                   if (dx != 0 or dy != 0)
  21.                   {
  22.                         int xx = wkx + dx;
  23.                         int yy = wky + dy;
  24.                         if (xx < 0 or xx >= 8 or yy < 0 or yy >= 8) continue;
  25.                         kingattack[xx][yy] = 1;
  26.                   }
  27.  
  28.       for (int i = 0; i < 8; i++) rookattack[wrx][i] = rookattack[i][wry] = 1;
  29.  
  30.       bool attacked = rookattack[bkx][bky];
  31.  
  32.       bool canmove = false;
  33.       for (int dx = -1; dx <= 1; dx++)
  34.             for (int dy = -1; dy <= 1; dy++)
  35.                   if (dx != 0 or dy != 0)
  36.                   {
  37.                         int xx = bkx + dx;
  38.                         int yy = bky + dy;
  39.                         if (xx < 0 or xx >= 8 or yy < 0 or yy >= 8) continue;
  40.                         canmove |= (kingattack[xx][yy] ^ 1) & (rookattack[xx][yy] ^ 1);
  41.                   }
  42.  
  43.       if (kingattack[bkx][bky]) puts("Strange");
  44.       else if (!attacked and canmove) puts("Normal");
  45.       else if (attacked and canmove) puts("Check");
  46.       else if (!attacked and !canmove) puts("Stalemate");
  47.       else if (attacked and !canmove) puts("Checkmate");
  48.       return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement