Advertisement
anas_harby

Untitled

Dec 17th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. char BWBoard[8][8];
  7. char piecesBoard[8][8] = {{'R','N','B','Q','K','B','N','R'}, {'P','P','P','P','P','P','P','P'},{},{},{},{},{'p','p','p','p','p','p','p','p'},{'r','n','b','q','k','b','n','r'}};
  8. char board[10][10];
  9. int turn=0, capturedBlack[16], capturedWhite[16], countBlack=0, countWhite=0;
  10.  
  11. void initializeBW();
  12. void userInput();
  13. void move(int iCurrent, int iDestination, int jCurrent, int jDestination);
  14. void printBoard();
  15. void capture(int iCurrent, int iDestination, int jCurrent, int jDestination);
  16. int validate(int iCurrent, int iDestination, int jCurrent, int jDestination);
  17. void printErrors(int, int, int, int, int);
  18.  
  19. int pawn(int iCurrent, int iDestination, int jCurrent, int jDestination);
  20. int knight(int iCurrent, int iDestination, int jCurrent, int jDestination);
  21. int rook(int iCurrent, int iDestination, int jCurrent, int jDestination);
  22. int bishop(int iCurrent, int iDestination, int jCurrent, int jDestination);
  23. int queen(int iCurrent, int iDestination, int jCurrent, int jDestination);
  24. int king(int iCurrent, int iDestination, int jCurrent, int jDestination);
  25.  
  26. int iBlackKing=0, iWhiteKing=7, jBlackKing=4, jWhiteKing=4;
  27. int checkerPieces[], checksCount;
  28. int check();
  29. int validateCheck(int iCurrent, int iDestination, int jCurrent, int jDestination);
  30. int checkmate();
  31. int checkMateFlag=0;
  32.  
  33. int main()
  34. {
  35. initializeBW();
  36.  
  37. while(checkmate()==0)
  38. {
  39. turn++;
  40. printBoard();
  41. userInput();
  42. printf("\n");
  43.  
  44.  
  45. }
  46. printf("CHECKMATE!\n");
  47. printf("%d %d", iWhiteKing, jWhiteKing);
  48. }
  49.  
  50.  
  51. void initializeBW ()
  52. {
  53. char c1 = '_', c2= '.';
  54. for(int i=0; i<8; i++)
  55. {
  56. for(int j=0; j<8; j+=2)
  57. {
  58. BWBoard[i][j] = c1;
  59. BWBoard[i][j+1] = c2;
  60. }
  61. char temp = c1;
  62. c1 = c2;
  63. c2 = temp;
  64. }
  65. }
  66.  
  67. void userInput()
  68. {
  69.  
  70. char inp[10];
  71. gets(inp);
  72. while(strlen(inp)!=4)
  73. {
  74. printf("Invalid Input!\n");
  75. gets(inp);
  76. }
  77. int iCurrent, iDestination, jCurrent, jDestination;
  78. jCurrent = (int)inp[0] - (int)'A';
  79. iCurrent = (int)inp[1] - (int)'0';
  80. jDestination = (int)inp[2] - (int)'A';
  81. iDestination = (int)inp[3] - (int)'0';
  82. iDestination = 8 - iDestination;
  83. iCurrent = 8 - iCurrent;
  84. if(validate(iCurrent, iDestination, jCurrent, jDestination)!=0)
  85. {
  86. printErrors(validate(iCurrent, iDestination, jCurrent, jDestination), iCurrent, iDestination, jCurrent, jDestination);
  87. userInput();
  88.  
  89. }
  90.  
  91. else if(validateCheck(iCurrent,iDestination,jCurrent,jDestination==1)) {
  92. printf("KING WILL BE CHECKED!\n");
  93. userInput();
  94. }
  95.  
  96. else if(validate(iCurrent, iDestination, jCurrent, jDestination)==0 && validateCheck(iCurrent,iDestination,jCurrent,jDestination)==0)
  97. {
  98. capture(iCurrent, iDestination, jCurrent, jDestination);
  99. move(iCurrent, iDestination, jCurrent, jDestination);
  100. }
  101. }
  102.  
  103.  
  104. void move(int iCurrent, int iDestination, int jCurrent, int jDestination)
  105. {
  106.  
  107. piecesBoard[iDestination][jDestination] = piecesBoard[iCurrent][jCurrent];
  108. piecesBoard[iCurrent][jCurrent]='\0';
  109. }
  110.  
  111. void printBoard()
  112. {
  113. board[0][0] = ' ', board[0][9] = ' ', board[9][0] = ' ', board[9][9] = ' ';
  114. for(int i=1; i<9; i++)
  115. {
  116. board[i][0] = 9-i;
  117. board[i][9]= 9-i;
  118. board[0][i] = 'A' +i-1;
  119. board[9][i] = 'A' +i-1;
  120.  
  121. }
  122.  
  123. for(int i=0; i<10; i++)
  124. {
  125. for(int j=0; j<10; j++)
  126. {
  127. if((board[i][j]>='A' && board[i][j] <= 'Z') || board[i][j]==' ')
  128. printf("%c\t", board[i][j]);
  129. else if((i>=1 && i<=8) && (j>=1 && j<=8))
  130. {
  131. if((piecesBoard[i-1][j-1]>='A' && piecesBoard[i-1][j-1]<='Z') || (piecesBoard[i-1][j-1]>='a' && piecesBoard[i-1][j-1]<='z'))
  132. printf("%c\t", piecesBoard[i-1][j-1]);
  133. else
  134. printf("%c\t", BWBoard[i-1][j-1]);
  135. }
  136. else
  137. printf("%d\t", (char)board[i][j]);
  138. }
  139. if(i==0||i==8)
  140. printf("\n\n\n");
  141. else
  142. printf("\n\n");
  143. }
  144. printf("\n\n\n");
  145. }
  146.  
  147.  
  148. int validate(int iCurrent, int iDestination, int jCurrent, int jDestination)
  149. {
  150. if ((jCurrent<0) || (jCurrent>7) || (jDestination<0) || (jDestination>7) || (iCurrent<0) || (iCurrent>7) || (iDestination<0) || (iDestination>7))
  151. {
  152. return 1;
  153. }
  154.  
  155. else if(turn%2!=0 && (piecesBoard[iCurrent][jCurrent]>='A' && piecesBoard[iCurrent][jCurrent]<='Z'))
  156. {
  157.  
  158. return 2;
  159. }
  160.  
  161. else if(turn%2==0 && (piecesBoard[iCurrent][jCurrent]>='a' && piecesBoard[iCurrent][jCurrent]<='z'))
  162. {
  163.  
  164. return 3;
  165. }
  166.  
  167. else if(piecesBoard[iCurrent][jCurrent]=='\0')
  168. {
  169.  
  170. return 4;
  171. }
  172.  
  173. else if(((piecesBoard[iCurrent][jCurrent]=='r')||(piecesBoard[iCurrent][jCurrent]=='R')) && (rook(iCurrent, iDestination, jCurrent, jDestination)==1))
  174. {
  175.  
  176. return 5;
  177. }
  178.  
  179. else if(((piecesBoard[iCurrent][jCurrent]=='p')||(piecesBoard[iCurrent][jCurrent]=='P')) && (pawn(iCurrent, iDestination, jCurrent, jDestination)==1))
  180. {
  181.  
  182. return 5;
  183. }
  184.  
  185. else if(((piecesBoard[iCurrent][jCurrent]=='b')||(piecesBoard[iCurrent][jCurrent]=='B')) && (bishop(iCurrent, iDestination, jCurrent, jDestination)==1))
  186. {
  187.  
  188. return 5;
  189. }
  190.  
  191. else if(((piecesBoard[iCurrent][jCurrent]=='q')||(piecesBoard[iCurrent][jCurrent]=='Q')) && (queen(iCurrent, iDestination, jCurrent, jDestination)==1))
  192. {
  193.  
  194. return 5;
  195. }
  196.  
  197. else if(((piecesBoard[iCurrent][jCurrent]=='k')||(piecesBoard[iCurrent][jCurrent]=='K')) && (king(iCurrent, iDestination, jCurrent, jDestination)==1))
  198. {
  199.  
  200. return 5;
  201. }
  202.  
  203. else if(((piecesBoard[iCurrent][jCurrent]=='n')||(piecesBoard[iCurrent][jCurrent]=='N')) && (knight(iCurrent, iDestination, jCurrent, jDestination)==1))
  204. {
  205.  
  206. return 5;
  207. }
  208.  
  209. else if (((piecesBoard[iCurrent][jCurrent]>='a') && (piecesBoard[iCurrent][jCurrent]<='z')) && ((piecesBoard[iDestination][jDestination]>='a') && (piecesBoard[iDestination][jDestination]<='z'))) {
  210.  
  211. return 5;
  212. }
  213.  
  214. else if (((piecesBoard[iCurrent][jCurrent]>='A') && (piecesBoard[iCurrent][jCurrent]<='Z')) && ((piecesBoard[iDestination][jDestination]>='A') && (piecesBoard[iDestination][jDestination]<='Z'))) {
  215.  
  216. return 5;
  217. }
  218.  
  219.  
  220.  
  221. else {
  222.  
  223. return 0;
  224. }
  225.  
  226.  
  227. }
  228.  
  229.  
  230.  
  231.  
  232.  
  233. void capture(int iCurrent, int iDestination, int jCurrent, int jDestination)
  234. {
  235. if(piecesBoard[iDestination][jDestination]>='a' && piecesBoard[iDestination][jDestination]<='z')
  236. {
  237. capturedWhite[countWhite] = piecesBoard[iDestination][jDestination];
  238. countWhite++;
  239. }
  240. else if(piecesBoard[iDestination][jDestination]>='A' && piecesBoard[iDestination][jDestination]<='Z')
  241. {
  242. capturedBlack[countBlack] = piecesBoard[iDestination][jDestination];
  243. countBlack++;
  244. }
  245. system("cls");
  246. printf("\nCaptured White Pieces: ");
  247. for(int i=0; i<countWhite; i++)
  248. printf("%c ", capturedWhite[i]);
  249. printf("\nCaptured Black Pieces: ");
  250. for(int i=0; i<countBlack; i++)
  251. printf("%c ", capturedBlack[i]);
  252. printf("\n\n");
  253. }
  254.  
  255.  
  256.  
  257.  
  258. int rook(int iCurrent, int iDestination, int jCurrent, int jDestination)
  259. {
  260. int count,flag=0;
  261. if((jCurrent==jDestination) && (iCurrent!= iDestination))
  262. {
  263. if (iDestination>iCurrent)
  264. {
  265. for (count=1; (((iCurrent+count)<iDestination)&&flag==0); count++)
  266. {
  267. if (piecesBoard[iCurrent+count][jCurrent]=='\0')
  268. {
  269. flag=0 ;
  270. }
  271. else
  272. {
  273. flag=1;
  274. }
  275. }
  276. }
  277. else
  278. {
  279. for(count=1; (((iCurrent-count)>iDestination)&&flag==0); count++)
  280. {
  281. if (piecesBoard[iCurrent-count][jCurrent]=='\0')
  282. {
  283. flag=0;
  284. }
  285. else
  286. {
  287. flag=1;
  288. }
  289. }
  290. }
  291. if (flag==0)
  292. {
  293. return 0;
  294. }
  295. else
  296. {
  297. return 1;
  298. }
  299. }
  300. else if((jCurrent!=jDestination) && (iCurrent==iDestination))
  301. {
  302. if (jDestination>jCurrent)
  303. {
  304. for (count=1; (((jCurrent+count)<jDestination)&&flag==0); count++)
  305. {
  306. if (piecesBoard[iCurrent][jCurrent+count]=='\0')
  307. {
  308. flag=0;
  309. }
  310. else
  311. {
  312. flag=1;
  313. }
  314. }
  315. }
  316. else
  317. {
  318. for (count=1; (jCurrent-count)>jDestination; count++)
  319. {
  320. if (piecesBoard[iCurrent][jCurrent-count]=='\0')
  321. {
  322. flag=0;
  323. }
  324. else
  325. {
  326. flag=1;
  327. }
  328. }
  329. }
  330. if (flag==0)
  331. {
  332. return 0;
  333. }
  334. else
  335. {
  336. return 1;
  337. }
  338. }
  339. else
  340. {
  341. return 1;
  342. }
  343. }
  344.  
  345.  
  346. int king(int iCurrent,int iDestination,int jCurrent,int jDestination)
  347. {
  348. int iDiff,jDiff;
  349. iDiff=iCurrent-iDestination;
  350. jDiff=jCurrent-jDestination;
  351. if (((iCurrent == iDestination) && (abs(jDiff)==1)) || ((jCurrent==jDestination) && (abs(iDiff)==1)) || (abs(iDiff)==1 && abs(jDiff)==1))
  352. {
  353. if(piecesBoard[iCurrent][jCurrent]=='k')
  354. {
  355. iWhiteKing = iDestination;
  356. jWhiteKing = jDestination;
  357.  
  358. }
  359. else if(piecesBoard[iCurrent][jCurrent]=='K')
  360. {
  361. iBlackKing = iDestination;
  362. jBlackKing = jDestination;
  363. }
  364. return 0;
  365. }
  366. else
  367. {
  368. return 1;
  369. }
  370. }
  371.  
  372. int bishop(int iCurrent,int iDestination,int jCurrent,int jDestination)
  373. {
  374. int iDiff,jDiff;
  375. int count=1,flag=0;
  376. iDiff=iDestination-iCurrent;
  377. jDiff=jDestination-jCurrent;
  378. int DeciCurrent,InciCurrent,DecjCurrent,IncjCurrent;
  379.  
  380. if (abs(iDiff)==abs(jDiff))
  381. {
  382. if (iDestination>iCurrent)
  383. {
  384. count=1;
  385. do
  386. {
  387. DecjCurrent=jCurrent-count;
  388. IncjCurrent=jCurrent+count;
  389. InciCurrent=iCurrent+count;
  390. if (InciCurrent<iDestination)
  391. {
  392. if (jDestination<jCurrent)
  393. {
  394. if (piecesBoard[InciCurrent][DecjCurrent]=='\0')
  395. {
  396. flag=0;
  397. }
  398. else
  399. {
  400. flag=1;
  401. }
  402.  
  403. }
  404. else if (jDestination>jCurrent)
  405. {
  406. if (piecesBoard[InciCurrent][IncjCurrent]=='\0')
  407. {
  408. flag=0;
  409. }
  410. else
  411. {
  412. flag=1;
  413. }
  414. }
  415. count++;
  416. }
  417. }
  418. while ((InciCurrent<iDestination) && (flag==0));
  419. if (flag==0)
  420. {
  421. return 0;
  422. }
  423. else
  424. {
  425. return 1;
  426. }
  427. }
  428.  
  429. else
  430. {
  431. count=1;
  432. do
  433. {
  434. DeciCurrent=iCurrent-count;
  435. DecjCurrent=jCurrent-count;
  436. IncjCurrent=jCurrent+count;
  437. if (DeciCurrent>iDestination)
  438. {
  439. if (jDestination<jCurrent)
  440. {
  441.  
  442. if (piecesBoard[DeciCurrent][DecjCurrent]=='\0')
  443. {
  444. flag=0;
  445. }
  446. else
  447. {
  448. flag=1;
  449. }
  450. }
  451. else if (jDestination>jCurrent)
  452. {
  453. if (piecesBoard[DeciCurrent][IncjCurrent]=='\0')
  454. {
  455. flag=0;
  456. }
  457. else
  458. {
  459. flag=1;
  460. }
  461. }
  462. count++;
  463.  
  464. }
  465. }
  466. while ((DeciCurrent>iDestination) && (flag==0));
  467.  
  468. if (flag==0)
  469. {
  470. return 0;
  471. }
  472. else
  473. {
  474. return 1;
  475. }
  476. }
  477.  
  478.  
  479. }
  480. else
  481. {
  482. return 1;
  483. }
  484.  
  485. }
  486.  
  487. int pawn(int iCurrent, int iDestination, int jCurrent, int jDestination)
  488. {
  489.  
  490. if(piecesBoard[iCurrent][jCurrent]=='p' && (jDestination==jCurrent) && (iDestination-iCurrent==-1))
  491. {
  492. if (piecesBoard[iDestination][jDestination]!='\0')
  493. {
  494. return 1;
  495. }
  496. else
  497. {
  498. return 0;
  499. }
  500. }
  501.  
  502. else if(piecesBoard[iCurrent][jCurrent]=='P' && (jDestination==jCurrent) && (iDestination-iCurrent==1))
  503. {
  504. if (piecesBoard[iDestination][jDestination]!='\0')
  505. {
  506. return 1;
  507. }
  508. else
  509. {
  510. return 0;
  511. }
  512. }
  513.  
  514. else if(piecesBoard[iCurrent][jCurrent]=='p' && iDestination-iCurrent==-1 && abs(jDestination-jCurrent)==1 && piecesBoard[iDestination][jDestination]>='A' && piecesBoard[iDestination][jDestination]<='Z')
  515. return 0;
  516.  
  517. else if(piecesBoard[iCurrent][jCurrent]=='P' && iDestination-iCurrent==1 && abs(jDestination-jCurrent)==1 && piecesBoard[iDestination][jDestination]>='a' && piecesBoard[iDestination][jDestination]<='z')
  518. return 0;
  519.  
  520. else if(piecesBoard[iCurrent][jCurrent]=='p' && iCurrent==6 && jCurrent==jDestination && (iDestination-iCurrent==-1 || iDestination-iCurrent==-2))
  521. return 0;
  522.  
  523. else if(piecesBoard[iCurrent][jCurrent]=='P' && iCurrent==1 && jCurrent==jDestination && (iDestination-iCurrent==1 || iDestination-iCurrent==2))
  524. return 0;
  525.  
  526. else
  527. return 1;
  528.  
  529. }
  530.  
  531.  
  532.  
  533. int queen(int iCurrent,int iDestination,int jCurrent,int jDestination)
  534. {
  535. int iDiff,jDiff;
  536. iDiff=iDestination-iCurrent;
  537. jDiff=jDestination-jCurrent;
  538.  
  539. if(((iDestination == iCurrent && jDestination != jCurrent) || (iDestination != iCurrent && jDestination == jCurrent))&& rook(iCurrent,iDestination,jCurrent,jDestination)==0)
  540.  
  541. return 0;
  542.  
  543.  
  544. else if (abs(iDiff)==abs(jDiff) && bishop(iCurrent, iDestination, jCurrent, jDestination)==0)
  545.  
  546. return 0;
  547.  
  548. else
  549.  
  550. return 1;
  551.  
  552. }
  553.  
  554. int knight(int iCurrent,int iDestination,int jCurrent,int jDestination)
  555. {
  556. int iDiff,jDiff;
  557. iDiff=iDestination-iCurrent;
  558. jDiff=jDestination-jCurrent;
  559. if ((abs(iDiff)==2) && (abs(jDiff)==1))
  560.  
  561. return 0;
  562.  
  563. else if ((abs(jDiff)==2) && (abs(iDiff)==1))
  564.  
  565. return 0;
  566.  
  567. else
  568.  
  569. return 1;
  570.  
  571. }
  572.  
  573.  
  574. int check()
  575. {
  576. int f=0;
  577.  
  578. for(int i=0; i<8; i++)
  579. {
  580. for(int j=0; j<8; j++)
  581. {
  582. if(turn%2==1)
  583. {
  584. if(validate(i, iBlackKing, j, jBlackKing)==0)
  585. {
  586. f=1;
  587. }
  588. }
  589.  
  590. else if(turn%2==0)
  591. {
  592. if(validate(i, iWhiteKing, j, jWhiteKing)==0)
  593. {
  594. f=1;
  595. }
  596. }
  597. }
  598. }
  599.  
  600. return f;
  601. }
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608. int checkmate()
  609. {
  610. int f=0;
  611. if(check()==1) {
  612.  
  613. if(turn%2==0) {
  614. if(validate(iWhiteKing, iWhiteKing+1, jWhiteKing, jWhiteKing)==0)
  615. f = f + validateCheck(iWhiteKing, iWhiteKing+1, jWhiteKing, jWhiteKing);
  616. else
  617. f = f+1;
  618. if(validate(iWhiteKing, iWhiteKing-1, jWhiteKing, jWhiteKing)==0)
  619. f = f + validateCheck(iWhiteKing, iWhiteKing-1, jWhiteKing, jWhiteKing);
  620. else
  621. f = f+1;
  622. if(validate(iWhiteKing, iWhiteKing, jWhiteKing, jWhiteKing+1)==0)
  623. f = f + validateCheck(iWhiteKing, iWhiteKing, jWhiteKing, jWhiteKing+1);
  624. else
  625. f = f+1;
  626. if(validate(iWhiteKing, iWhiteKing, jWhiteKing, jWhiteKing-1)==0)
  627. f = f + validateCheck(iWhiteKing, iWhiteKing, jWhiteKing, jWhiteKing-1);
  628. else
  629. f = f+1;
  630. if(validate(iWhiteKing, iWhiteKing+1, jWhiteKing, jWhiteKing+1)==0)
  631. f = f + validateCheck(iWhiteKing, iWhiteKing+1, jWhiteKing, jWhiteKing+1);
  632. else
  633. f = f+1;
  634. if(validate(iWhiteKing, iWhiteKing-1, jWhiteKing, jWhiteKing-1)==0)
  635. f = f + validateCheck(iWhiteKing, iWhiteKing-1, jWhiteKing, jWhiteKing-1);
  636. else
  637. f = f+1;
  638. if(validate(iWhiteKing, iWhiteKing-1, jWhiteKing, jWhiteKing+1)==0)
  639. f = f + validateCheck(iWhiteKing, iWhiteKing-1, jWhiteKing, jWhiteKing+1);
  640. else
  641. f = f+1;
  642. if(validate(iWhiteKing, iWhiteKing+1, jWhiteKing, jWhiteKing-1)==0)
  643. f = f + validateCheck(iWhiteKing, iWhiteKing+1, jWhiteKing, jWhiteKing-1);
  644. else
  645. f = f+1;
  646. }
  647. else if(turn%2==1) {
  648. if(validate(iBlackKing, iBlackKing+1, jBlackKing, jBlackKing)==0)
  649. f = f + validateCheck(iBlackKing, iBlackKing+1, jBlackKing, jBlackKing);
  650. else
  651. f = f+1;
  652. if(validate(iBlackKing, iBlackKing-1, jBlackKing, jBlackKing)==0)
  653. f = f + validateCheck(iBlackKing, iBlackKing-1, jBlackKing, jBlackKing);
  654. else
  655. f = f+1;
  656. if(validate(iBlackKing, iBlackKing, jBlackKing, jBlackKing+1)==0)
  657. f = f + validateCheck(iBlackKing, iBlackKing, jBlackKing, jBlackKing+1);
  658. else
  659. f = f+1;
  660. if(validate(iBlackKing, iBlackKing, jBlackKing, jBlackKing-1)==0)
  661. f = f + validateCheck(iBlackKing, iBlackKing, jBlackKing, jBlackKing-1);
  662. else
  663. f = f+1;
  664. if(validate(iBlackKing, iBlackKing+1, jBlackKing, jBlackKing+1)==0)
  665. f = f + validateCheck(iBlackKing, iBlackKing+1, jBlackKing, jBlackKing+1);
  666. else
  667. f = f+1;
  668. if(validate(iBlackKing, iBlackKing-1, jBlackKing, jBlackKing-1)==0)
  669. f = f + validateCheck(iBlackKing, iBlackKing-1, jBlackKing, jBlackKing-1);
  670. else
  671. f = f+1;
  672. if(validate(iBlackKing, iBlackKing-1, jBlackKing, jBlackKing+1)==0)
  673. f = f + validateCheck(iBlackKing, iBlackKing-1, jBlackKing, jBlackKing+1);
  674. else
  675. f = f+1;
  676. if(validate(iBlackKing, iBlackKing+1, jBlackKing, jBlackKing-1)==0)
  677. f = f + validateCheck(iBlackKing, iBlackKing+1, jBlackKing, jBlackKing-1);
  678. else
  679. f = f+1;
  680. }
  681.  
  682. if(f==8)
  683. return 1;
  684. else
  685. return 0;
  686.  
  687. }
  688.  
  689. }
  690.  
  691.  
  692. void printErrors(int f, int iCurrent, int iDestination, int jCurrent, int jDestination)
  693. {
  694. f = validate(iCurrent, iDestination, jCurrent, jDestination);
  695. switch(f)
  696. {
  697. case 0:
  698. break;
  699.  
  700. case 1:
  701. printf("Invalid Input!\n");
  702. break;
  703. case 2:
  704. printf("White Pieces Turn!\n");
  705. break;
  706. case 3:
  707. printf("Black Pieces Turn!\n");
  708. break;
  709. case 4:
  710. printf("Empty Position!\n");
  711. break;
  712. case 5:
  713. printf("Wrong Move!\n");
  714. break;
  715. }
  716.  
  717. }
  718.  
  719.  
  720. int validateCheck(int iCurrent, int iDestination, int jCurrent, int jDestination)
  721. {
  722. int tempiBlackKing = iBlackKing;
  723. int tempjBlackKing = jBlackKing;
  724. int tempiWhiteKing = iWhiteKing;
  725. int tempjWhiteKing = jWhiteKing;
  726.  
  727. char tempPiece;
  728. int f=0, fC=0;
  729.  
  730. if(piecesBoard[iDestination][jDestination]!='\0') {
  731. tempPiece = piecesBoard[iDestination][jDestination];
  732. fC=1;
  733. }
  734. move(iCurrent, iDestination, jCurrent, jDestination);
  735. turn++;
  736. if(check()==1) {
  737. f=1;
  738. }
  739.  
  740. move(iDestination, iCurrent, jDestination, jCurrent);
  741. if(fC=1) {
  742. piecesBoard[iDestination][jDestination] = tempPiece;
  743. }
  744. turn--;
  745. return f;
  746.  
  747.  
  748. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement