Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <windows.h>
  5. #include <math.h>
  6. /*Used Variables c,k,n,char temp*/
  7. int k=0,n=0,g=2,xk=8,xK=1;
  8. char board[8][8],yk='E',yK='E',p;
  9. int c=1;
  10. int x1,x2;
  11. char eaten1[16]={' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
  12. char eaten2[16]={' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
  13. char index1[8]={'A','B','C','D','E','F','G','H'};
  14. int index2[8]={1,2,3,4,5,6,7,8};
  15. int valid(int x1,char y1,int x2,char y2);
  16. int removecheckwhite (int x1,char y1,int x2,char y2);
  17. int removecheckblack(int x1,char y1,int x2,char y2);
  18. int checkTurns(int x1,char y1);
  19. int check1 (int xk,char yk,int xK,char yK);
  20. int checkwhite (int xk,char yk,int xK,char yK);
  21. int checkblack (int xk,char yk,int xK,char yK);
  22. int stalemateWhite(int);
  23. int stalemateBlack(int);
  24.  
  25.  
  26.  
  27. void gotoxy(int x, int y)
  28. {
  29. COORD coord;
  30. coord.X = x;
  31. coord.Y = y;
  32. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  33. }
  34. void delay(unsigned int mseconds)
  35. {
  36. clock_t goal = mseconds + clock();
  37. while (goal > clock());
  38. }
  39. int main()
  40. {
  41. char y1,y2,mode,temp;
  42. /*Initializing the initial board*/
  43. for(int i=0;i<2;i++)
  44. {
  45. if(i==1)
  46. {
  47. for(int j=0;j<8;j++)
  48. {
  49. board[i][j]='P';
  50. }
  51. }
  52. else
  53. {
  54. for(int j=0;j<8;j++)
  55. {
  56. switch (j)
  57. {
  58. case 0: board[i][j]='R'; break;
  59. case 1: board[i][j]='N'; break;
  60. case 2: board[i][j]='B'; break;
  61. case 3: board[i][j]='Q'; break;
  62. case 4: board[i][j]='K'; break;
  63. case 5: board[i][j]='B'; break;
  64. case 6: board[i][j]='N'; break;
  65. case 7: board[i][j]='R'; break;
  66. }
  67. }
  68. }
  69. }
  70. for(int i=6;i<8;i++)
  71. {
  72. if(i==6)
  73. {
  74. for(int j=0;j<8;j++)
  75. {
  76. board[i][j]='p';
  77. }
  78. }
  79. else
  80. {
  81. for(int j=0;j<8;j++)
  82. {
  83. switch (j)
  84. {
  85. case 0: board[i][j]='r'; break;
  86. case 1: board[i][j]='n'; break;
  87. case 2: board[i][j]='b'; break;
  88. case 3: board[i][j]='q'; break;
  89. case 4: board[i][j]='k'; break;
  90. case 5: board[i][j]='b'; break;
  91. case 6: board[i][j]='n'; break;
  92. case 7: board[i][j]='r'; break;
  93. }
  94. }
  95. }
  96. }
  97. for(int i=2;i<6;i++)
  98. {
  99. for(int j=0;j<8;j++)
  100. {
  101. if ((i+j)%2==1)
  102. board[i][j]=' ';
  103. else
  104. board[i][j]=219;
  105. }
  106. }
  107. /*End of Assiging Values*/
  108. /*Printing the board at the begining*/
  109. printf("\n\n");
  110. printf(" Eaten Pieces Of Player (1) ");
  111. for(int i=0;i<16;i++)
  112. {
  113. printf("%c|",eaten1[i]);
  114. }
  115. printf("\n");
  116. printf(" Eaten Pieces Of Player (2) ");
  117. for(int i=0;i<16;i++)
  118. {
  119. printf("%c|",eaten2[i]);
  120. }
  121. printf("\n\n\n\n");
  122. printf(" Player {2} Black\n\n");
  123.  
  124. printf(" ");
  125. for(int i=0;i<8;i++)
  126. {
  127. printf(" .%c.",index1[i]);
  128. }
  129. printf("\n");
  130. for(int row=0;row<8;row++)
  131. {
  132. /* Draw the top line */
  133. printf(" ");
  134. for(int column=0;column<8;column++)
  135. printf(" ---");
  136. putchar('\n');
  137. /* Draw the squares */
  138. printf(" ");
  139. printf("%d",c++);
  140. for(int column=0;column<8;column++)
  141. {
  142. printf("| %c ",board[row][column]);
  143. }
  144. printf("|\n");
  145. }
  146. printf(" ");
  147. for(int column=0;column<8;column++)
  148. printf(" ---");
  149. printf("\n\n");
  150. printf(" Player {1} White ");
  151. printf("\n\n");
  152. /* End of Printing the board before playing*//*Printing the board before playing*//*Printing the board before playing*/
  153. printf("Enter the desired piece\n");
  154. scanf("%d %c",&x1,&y1);
  155. printf("Enter the desired destination\n");
  156. scanf("%d %c",&x2,&y2);
  157.  
  158. while((valid(x1,y1,x2,y2)==0 || checkTurns(x1,y1)==0)){
  159. printf("NOT VALID MOVE\n");
  160. printf("Enter the desired piece\n");
  161. scanf("%d %c",&x1,&y1);
  162. printf("Enter the desired destination\n");
  163. scanf("%d %c",&x2,&y2);}
  164. g++;
  165. x1=x1-1;
  166. x2=x2-1;
  167. y1=y1-65;
  168. y2=y2-65;
  169. temp=board[x2][y2];
  170. board[x2][y2]=board[x1][y1];
  171. if((x1+y1)%2==1)
  172. {
  173. board[x1][y1]=' ';
  174. }
  175. else
  176. {
  177. board[x1][y1]=219;
  178. }
  179. /*Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooor*/
  180. for(;;)
  181. {
  182.  
  183. system("cls");
  184. if(check1(xk,yk,xK,yK)!=0){printf("CHECK!");}
  185.  
  186. int c=1;
  187. /*Printing The Board At Every Move*/
  188. printf("\n\n");
  189. printf(" Eaten Pieces Of Player (1) ");
  190. for(int i=0;i<16;i++)
  191. {
  192. printf("%c|",eaten1[i]);
  193. }
  194. printf("\n");
  195. printf(" Eaten Pieces Of Player (2) ");
  196. for(int i=0;i<16;i++)
  197. {
  198. printf("%c|",eaten2[i]);
  199. }
  200. printf("\n\n\n\n");
  201. printf(" Player {2} Black\n\n");
  202.  
  203. printf(" ");
  204. for(int i=0;i<8;i++)
  205. {
  206. printf(" .%c.",index1[i]);
  207. }
  208. printf("\n");
  209. for(int row=0;row<8;row++)
  210. {
  211. /* Draw the top line */
  212. printf(" ");
  213. for(int column=0;column<8;column++)
  214. printf(" ---");
  215. putchar('\n');
  216. /* Draw the squares */
  217. printf(" ");
  218. printf("%d",c++);
  219. for(int column=0;column<8;column++)
  220. {
  221. printf("| %c ",board[row][column]);
  222. }
  223. printf("|\n");
  224. }
  225. printf(" ");
  226. for(int column=0;column<8;column++)
  227. printf(" ---");
  228. printf("\n\n");
  229. printf(" Player {1} White ");
  230. printf("\n\n");
  231. /*End of Printing The Board At Every Move*/
  232.  
  233.  
  234. if(checkblack(xk,yk,xK,yK)==1 && check1(xk,yk,xK,yK)==1)
  235. {
  236. printf("Player 1 wins\n");
  237. break;
  238.  
  239. }
  240. if(checkwhite(xk,yk,xK,yK)==1 && check1(xk,yk,xK,yK)==2)
  241. {
  242. printf("Player 2 wins\n");
  243. break;
  244. }
  245.  
  246. if(stalemateWhite(1)==1 || stalemateBlack(1)==1)
  247. {
  248. printf("IT'S A STALEMATE");
  249. break;
  250. }
  251. printf("To Move Press (M) , To Undo Press (U), To Redo Press (R)\n");
  252. mode=getch();
  253. if(mode=='U')
  254. {
  255. board[x1][y1]=board[x2][y2];
  256. board[x2][y2]=temp;
  257. }
  258. else if(mode=='R')
  259. {
  260.  
  261. }
  262. else
  263. {
  264.  
  265. printf("Enter the desired piece\n");
  266. scanf("%d %c",&x1,&y1);
  267. printf("Enter the desired destination\n");
  268. scanf("%d %c",&x2,&y2);
  269.  
  270. while(valid(x1,y1,x2,y2)==0){
  271. printf("NOT VALID MOVE\n");
  272. printf("Enter the desired piece\n");
  273. scanf("%d %c",&x1,&y1);
  274. printf("Enter the desired destination\n");
  275. scanf("%d %c",&x2,&y2);}
  276.  
  277. if(board[x1-1][y1-65]=='k'){xk=x2;
  278. yk=y2;}
  279. if(board[x1-1][y1-65]=='K'){xK=x2;
  280. yK=y2;}
  281.  
  282. //check(xk,yk,xK,yK);
  283. x1=x1-1;
  284. x2=x2-1;
  285. y1=y1-65;
  286. y2=y2-65;
  287. /*Printing Eaten if Exist */
  288. if((board[x2][y2]>=97 && board[x2][y2]<=122))
  289. {
  290. eaten1[k]=board[x2][y2];
  291. k++;
  292. }
  293. if((board[x2][y2]>=65 && board[x2][y2]<=90))
  294. {
  295. eaten2[n]=board[x2][y2];
  296. n++;
  297. }
  298. /*Printing Eaten if Exist */
  299. temp=board[x2][y2];
  300. board[x2][y2]=board[x1][y1];
  301. if((x1+y1)%2==1)
  302. {
  303. board[x1][y1]=' ';
  304. }
  305. else
  306. {
  307. board[x1][y1]=219;
  308. }
  309.  
  310. /*black*/
  311. while(check1(xk,yk,xK,yK)==1 && (board[x2][y2]>=65 && board[x2][y2]<=90))
  312. {
  313. board[x1][y1]=board[x2][y2];
  314. board[x2][y2]=temp;
  315. if(board[x1][y1]=='k'){xk=x1+1;
  316. yk=y1+65;}
  317. if(board[x1][y1]=='K'){xK=x1+1;
  318. yK=y1+65;}
  319. printf("CHECK!\n");
  320. printf("Enter the desired piece\n");
  321. scanf("%d %c",&x1,&y1);
  322. printf("Enter the desired destination\n");
  323. scanf("%d %c",&x2,&y2);
  324.  
  325. if(board[x1-1][y1-65]=='k'){xk=x2;
  326. yk=y2;}
  327. if(board[x1-1][y1-65]=='K'){xK=x2;
  328. yK=y2;}
  329.  
  330. x1=x1-1;
  331. x2=x2-1;
  332. y1=y1-65;
  333. y2=y2-65;
  334. temp=board[x2][y2];
  335. board[x2][y2]=board[x1][y1];}
  336.  
  337.  
  338. }
  339. while(check1(xk,yk,xK,yK)==2 && (board[x2][y2]>=97 && board[x2][y2]<=122))
  340. {
  341. board[x1][y1]=board[x2][y2];
  342. board[x2][y2]=temp;
  343. if(board[x1][y1]=='k'){xk=x1+1;
  344. yk=y1+65;}
  345. if(board[x1][y1]=='K'){xK=x1+1;
  346. yK=y1+65;}
  347. printf("CHECK!\n");
  348. printf("Enter the desired piece\n");
  349. scanf("%d %c",&x1,&y1);
  350. printf("Enter the desired destination\n");
  351. scanf("%d %c",&x2,&y2);
  352.  
  353. if(board[x1-1][y1-65]=='k'){xk=x2;
  354. yk=y2;}
  355. if(board[x1-1][y1-65]=='K'){xK=x2;
  356. yK=y2;}
  357. x1=x1-1;
  358. x2=x2-1;
  359. y1=y1-65;
  360. y2=y2-65;
  361. temp=board[x2][y2];
  362. board[x2][y2]=board[x1][y1];}
  363.  
  364.  
  365.  
  366.  
  367.  
  368. if((x1+y1)%2==1)
  369. {
  370. board[x1][y1]=' ';
  371. }
  372. else
  373. {
  374. board[x1][y1]=219;
  375. }
  376. }
  377. return 0;
  378.  
  379. }
  380.  
  381.  
  382.  
  383.  
  384. int valid(int x1,char y1,int x2,char y2)
  385. {
  386. int condition=1,i,t1=0,t2=0; char tempo;
  387. y1=y1-65;
  388. y2=y2-65;
  389. x1=x1-1;
  390. x2=x2-1;
  391. char w[6]={'p','r','n','b','k','q'};
  392. char b[6]={'P','R','N','B','K','Q'};
  393. char c=219,tempq;
  394. if(board[x1][y1]=='b'||board[x1][y1]=='B'){
  395. if(abs(x2-x1)!=abs(y2-y1)){condition=0;}}
  396. else if(board[x1][y1]=='n'||board[x1][y1]=='N')
  397. {
  398. if(!((abs(x2-x1)==1&&abs(y2-y1)==2)||(abs(y2-y1)==1&&abs(x2-x1)==2))){condition=0;}
  399. }
  400. else if(board[x1][y1]=='r'||board[x1][y1]=='R')
  401. {
  402. if(x1!=x2&&y1!=y2){condition=0;}
  403. }
  404. else if(board[x1][y1]=='K'||board[x1][y1]=='k')
  405. {
  406. if(abs(x2-x1)>=2||abs(y2-y1)>=2){condition=0;}
  407. }
  408. else if(board[x1][y1]=='p'){
  409. if(!(x1-x2==1&&y1==y2)){condition=0;}
  410. }
  411. else if(board[x1][y1]=='P'){
  412. if(!(x2-x1==1&&y1==y2)){condition=0;}
  413. }
  414. else if(board[x1][y1]=='q'||board[x1][y1]=='Q')
  415. {
  416. if((abs(x2-x1)!=abs(y2-y1))&&(x1!=x2&&y1!=y2)){condition=0;}
  417. }
  418. for(i=0;i<6;i++){
  419. if(board[x1][y1]==w[i]){t1=1;}}
  420. for(i=0;i<6;i++){
  421. if(board[x2][y2]==w[i]){t2=1;}}
  422. if(t1==1&&t2==1){condition=0;}
  423. t1=0;
  424. t2=0;
  425. for(i=0;i<6;i++){
  426. if(board[x1][y1]==b[i]){t1=1;}}
  427. for(i=0;i<6;i++){
  428. if(board[x2][y2]==b[i]){t2=1;}}
  429. if(t1==1&&t2==1){condition=0;}
  430. if(board[x1][y1]==' '||board[x1][y1]==c){condition=0;}
  431. t1=0;
  432. t2=0;
  433. if(board[x1][y1]=='p'&&(x1-x2)==1&&abs(y2-y1)==1)
  434. {
  435. for(i=0;i<6;i++){
  436. if(board[x2][y2]==b[i]){condition=1;}}}
  437. if(board[x1][y1]=='P'&&(x2-x1)==1&&abs(y2-y1)==1)
  438. {
  439. for(i=0;i<6;i++){
  440. if(board[x2][y2]==w[i]){condition=1;}}}
  441. i=1,t1=0,t2=0;
  442. if((board[x1][y1]=='b'||board[x1][y1]=='B')&&condition==1)
  443. {
  444. if(x2>x1&&y2>y1){
  445. while(x1+i!=x2){
  446. if(board[x1+i][y1+i]!=' '&&board[x1+i][y1+i]!=c){t1=1;}
  447. i++;}
  448. if(t1==1){condition=0;}}
  449.  
  450. else if(x2>x1&&y2<y1){
  451. t1=0,i=1;
  452. while(x1+i!=x2){
  453. if(board[x1+i][y1-i]!=' '&&board[x1+i][y1-i]!=c){t1=1;}
  454. i++;}
  455. if(t1==1){condition=0;}}
  456.  
  457. else if(x2<x1&&y2<y1){
  458. t1=0,i=1;
  459. while(x1-i!=x2){
  460. if(board[x1-i][y1-i]!=' '&&board[x1-i][y1-i]!=c){t1=1;}
  461. i++;}
  462. if(t1==1){condition=0;}}
  463.  
  464. else if(x2<x1&&y2>y1){
  465. t1=0,i=1;
  466. while(x1-i!=x2){
  467. if(board[x1-i][y1+i]!=' '&&board[x1-i][y1+i]!=c){t1=1;}
  468. i++;}
  469. if(t1==1){condition=0;}}
  470. t1=0,i=1;}
  471. if((board[x1][y1]=='r'||board[x1][y1]=='R')&&condition==1){
  472. if(x2>x1){
  473. i=1,t1=0;
  474. while(x1+i!=x2){
  475. if(board[x1+i][y1]!=' '&&board[x1+i][y1]!=c){t1=1;}
  476. i++;}
  477. if(t1==1){condition=0;}}
  478. if(x2<x1){
  479. i=1,t1=0;
  480. while(x1-i!=x2){
  481. if(board[x1-i][y1]!=' '&&board[x1-i][y1]!=c){t1=1;}
  482. i++;}
  483. if(t1==1){condition=0;}}
  484. if(y2>y1){
  485. i=1,t1=0;
  486. while(y1+i!=y2){
  487. if(board[x1][y1+i]!=' '&&board[x1][y1+i]!=c){t1=1;}
  488. i++;}
  489. if(t1==1){condition=0;}}
  490. if(y2<y1){
  491. i=1,t1=0;
  492. while(y1-i!=y2){
  493. if(board[x1][y1-i]!=' '&&board[x1][y1-i]!=c){t1=1;}
  494. i++;}
  495. if(t1==1){condition=0;}}}
  496. if(board[x1][y1]=='q'&&condition==1){
  497. if(abs(x2-x1)==abs(y2-y1)){
  498. tempq=board[x1][y1];
  499. board[x1][y1]='b';
  500. if(valid(x1+1,y1+65,x2+1,y2+65)==0){condition=0;}
  501. board[x1][y1]=tempq;}
  502. else {
  503. tempq=board[x1][y1];
  504. board[x1][y1]='r';
  505. if(valid(x1+1,y1+65,x2+1,y2+65)==0){condition=0;}
  506. board[x1][y1]=tempq;}}
  507. if(board[x1][y1]=='Q'&&condition==1){
  508. if(abs(x2-x1)==abs(y2-y1)){
  509. tempq=board[x1][y1];
  510. board[x1][y1]='B';
  511. if(valid(x1+1,y1+65,x2+1,y2+65)==0){condition=0;}
  512. board[x1][y1]=tempq;}
  513. else {
  514. tempq=board[x1][y1];
  515. board[x1][y1]='R';
  516. if(valid(x1+1,y1+65,x2+1,y2+65)==0){condition=0;}
  517. board[x1][y1]=tempq;}}
  518.  
  519. if(x1>=8||x1<0||y1>=8||y1<0||x2>=8||x2<0||y2>=8||y2<0){condition=0;}
  520.  
  521. if(board[x1][y1]=='P'&&condition==0){
  522. if((x2-x1)==2&&x1==1&&y1==y2&&(board[x2][y2]==' '||board[x2][y2]==c)){condition=1;}}
  523.  
  524. if(board[x1][y1]=='p'&&condition==0){
  525. if((x1-x2)==2&&x1==6&&y1==y2&&(board[x2][y2]==' '||board[x2][y2]==c)){condition=1;}}
  526.  
  527. /* if(board[x1][y1]=='P'&&condition==1&&y1==y2)
  528. {
  529. if(((x2-x1)==1)&&(board[x2][y2]!=' '&&board[x2][y2]!=c)){condition=0;}
  530. }
  531.  
  532. if(board[x1][y1]=='p'&&condition==1&&y1==y2)
  533. {
  534. if(((x1-x2)==1)&&(board[x2][y2]!=' '&&board[x2][y2]!=c)){condition=0;}
  535. }*/
  536. if((board[x1][y1]=='k')&& (check1(x2+1,y2+65,xK,yK)==2)){condition=0;}
  537.  
  538. if((board[x1][y1]=='K')&&(check1(xk,yk,x2+1,y2+65)==1)){condition=0;}
  539.  
  540.  
  541.  
  542. return condition;
  543. }
  544. int check1(int xk,char yk,int xK,char yK)
  545. { int i,j,k,check=0,t1,t2;
  546. char temp;
  547. char w[6]={'q','r','n','b','p','k'};
  548. char b[6]={'Q','R','N','B','P','K'};
  549. for(t1=0;t1<5;t1++)
  550. {
  551.  
  552. for(i=0;i<8;i++)
  553. {
  554. for(j=0;j<8;j++)
  555. {
  556. if(w[t1]==board[i][j])
  557. {
  558. if(valid(i+1,j+65,xK,yK)==1)
  559. {
  560. check=1;
  561. break;
  562. }
  563. }
  564. if(b[t1]==board[i][j])
  565. {
  566. if(valid(i+1,j+65,xk,yk)==1)
  567. {
  568. check=2;
  569. break;
  570. }
  571. }
  572. }
  573. }
  574. }
  575. return check;
  576. }
  577.  
  578.  
  579.  
  580. int checkTurns(int x1,char y1)
  581. {
  582. int turn=1;
  583. /*Validity of turns*/
  584. y1=y1-65;
  585. x1=x1-1;
  586. if((board[x1][y1]>=65 && board[x1][y1]<=90) && (g%2)==0){turn=0;}
  587. if((board[x1][y1]>=97 && board[x1][y1]<=122)&&(g%2)==1){turn=0;}
  588.  
  589. return turn;
  590. }
  591.  
  592. int checkblack (int xk,char yk,int xK,char yK)
  593. {
  594. int i,j,t2,mate=1,t1;
  595. char tempz;
  596.  
  597. if(check1(xk,yk,xK,yK)==1)
  598. {
  599.  
  600. for(i=0;i<8;i++) //black//
  601. {
  602. for(j=0;j<8;j++)
  603. {
  604. if(i+1==xK&&j+65==yK){continue;}
  605. if(board[i][j]>=65 && board[i][j]<=90)
  606. {
  607.  
  608. for(t1=0;t1<8;t1++)
  609. {
  610. for(t2=0;t2<8;t2++)
  611. {
  612. if(valid(i+1,j+65,t1+1,t2+65)==1)
  613. {
  614. tempz=board[t1][t2];
  615. board[t1][t2]=board[i][j];
  616. if(check1(xk,yk,xK,yK)==0)
  617. {
  618. mate=0; printf("%d %d \n",i,j);
  619. printf("%d %d\n",t1,t2);
  620.  
  621. }
  622. board[i][j]=board[t1][t2];
  623. board[t1][t2]=tempz;
  624.  
  625.  
  626. }
  627. }
  628. }
  629. }
  630. }
  631. }
  632. for(t1=-1;t1<2;t1++)
  633. {
  634. for(t2=-1;t2<2;t2++)
  635. {
  636. if(valid(xK,yK,xK+t1,yK+t2)==1)
  637. {
  638. tempz=board[xK+t1-1][yK+t2-65];
  639. board[xK+t1-1][yK+t2-65]=board[xK-1][yK-65];
  640. board[xK-1][yK-65]=219;
  641. if(check1(xk,yk,xK+t1,yK+t2)==0)
  642. {
  643. mate=0; printf("%d %d\n",t1,t2);
  644. }
  645. board[xK-1][yK-65]=board[xK+t1-1][yK+t2-65];
  646. board[xK+t1-1][yK+t2-65]=tempz;
  647.  
  648.  
  649. }
  650.  
  651.  
  652.  
  653.  
  654. }
  655. }
  656. }
  657.  
  658.  
  659.  
  660. return mate;
  661. }
  662.  
  663. int checkwhite(int xk,char yk,int xK,char yK)
  664. {
  665. int i,j,t2,mate=1,t1;
  666. char tempz;
  667.  
  668. if (check1(xk,yk,xK,yK)==2)
  669. {
  670. for(i=0;i<8;i++) //white
  671. {
  672. for(j=0;j<8;j++)
  673. {
  674. if(i+1==xk&&j+65==yk){continue;}
  675. if(board[i][j]>=97 && board[i][j]<=122)
  676. {
  677.  
  678. for(t1=0;t1<8;t1++)
  679. {
  680. for(t2=0;t2<8;t2++)
  681. {
  682. if(valid(i+1,j+65,t1+1,t2+65)==1)
  683. {
  684. tempz=board[t1][t2];
  685. board[t1][t2]=board[i][j];
  686. if(check1(xk,yk,xK,yK)==0)
  687. {
  688. mate=0; printf("%d %d \n",i,j);
  689. printf("%d %d\n",t1,t2);
  690.  
  691. }
  692. board[i][j]=board[t1][t2];
  693. board[t1][t2]=tempz;
  694. }
  695. }
  696. }
  697. }
  698. }
  699. }
  700. for(t1=-1;t1<2;t1++)
  701. {
  702. for(t2=-1;t2<2;t2++)
  703. {
  704.  
  705. if(valid(xk,yk,xk+t1,yk+t2)==1)
  706. {
  707. tempz=board[xk+t1-1][yk+t2-65];
  708. board[xk+t1-1][yk+t2-65]=board[xk-1][yk-65];
  709. board[xk-1][yk-65]=219;
  710.  
  711. if(check1(xk+t1,yk+t2,xK,yK)==0)
  712. {
  713. mate=0;
  714. printf("%d %d\n",t1,t2);
  715. printf("%c",board[xk+t1-1][yk+t2-65]);
  716. }
  717. board[xk-1][yk-65]=board[xk+t1-1][yk+t2-65];
  718. board[xk+t1-1][yk+t2-65]=tempz;
  719.  
  720.  
  721. }
  722. }
  723. }
  724.  
  725.  
  726. }
  727.  
  728. return mate;
  729.  
  730. }
  731.  
  732. int removecheckwhite (int x1,char y1,int x2,char y2)
  733. {
  734. int condition=1; char tempo;
  735. y1=y1-65;
  736. y2=y2-65;
  737. x1=x1-1;
  738. x2=x2-1;
  739. if(board[x1][y1]>=97 && board[x1][y1]<=122)
  740. {
  741. tempo=board[x2][y2];
  742. board[x2][y2]=board[x1][y1];
  743. if(check1(xk,yk,xK,yK)==2)
  744. {
  745. condition=0;
  746. }
  747. board[x1][y1]=board[x2][y2];
  748. board[x2][y2]=tempo;
  749. }
  750. return condition;
  751. }
  752.  
  753. int removecheckblack(int x1,char y1,int x2,char y2)
  754. {
  755.  
  756. int condition=1; char tempo;
  757. y1=y1-65;
  758. y2=y2-65;
  759. x1=x1-1;
  760. x2=x2-1;
  761.  
  762. if(board[x1][y1]>=65 && board[x1][y1]<=90)
  763. {
  764. tempo=board[x2][y2];
  765. board[x2][y2]=board[x1][y1];
  766. if(check1(xk,yk,xK,yK)==1)
  767. {
  768. condition=0;
  769. }
  770. board[x1][y1]=board[x2][y2];
  771. board[x2][y2]=tempo;
  772. }
  773. return condition;
  774.  
  775. }
  776.  
  777. int stalemateWhite(int a)
  778. {
  779. int i,j,stale=1,t1,t2;
  780. char w[6]={'q','r','n','b','p','k'};
  781. char b[6]={'Q','R','N','B','P','K'};
  782.  
  783. for(i=0;i<8;i++)
  784. {
  785. for(j=0;j<8;j++)
  786. {
  787. if(board[i][j]>=97 && board[i][j]<=122) //WHITE//
  788. {
  789. for(t1=0;t1<8;t1++)
  790. {
  791. for(t2=0;t2<8;t2++)
  792. {
  793. if(valid(i+1,j+65,t1+1,t2+65)==1 && removecheckwhite(i+1,j+65,t1+1,t2+65)==1)
  794. {
  795. stale=0;
  796. printf("%d %c \n",i+1,j+65);
  797. }
  798.  
  799. }
  800. }
  801. }
  802. }
  803. }
  804.  
  805. return stale;
  806. }
  807. int stalemateBlack(int a)
  808. {
  809.  
  810. int i,j,stale=1,t1,t2;
  811.  
  812. for(i=0;i<8;i++)
  813. {
  814. for(j=0;j<8;j++)
  815. {
  816. if(board[i][j]>=65 && board[i][j]<=90)
  817. {
  818. for(t1=0;t1<8;t1++)
  819. {
  820. for(t2=0;t2<8;t2++)
  821. {
  822. if(valid(i+1,j+65,t1+1,t2+65)==1 && removecheckblack(i+1,j+65,t1+1,t2+65)==1)
  823. {
  824. stale=0;
  825. printf("%d %c \n",i+1,j+65);
  826. }
  827.  
  828. }
  829. }
  830. }
  831. }
  832. }
  833.  
  834.  
  835.  
  836. return stale;
  837.  
  838. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement