Advertisement
Seif45

FINAL

Dec 14th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. char pieces[12][12];
  6. char gameBoard [12][12];
  7. char deadPieces[37];
  8. char play[5];
  9. int index[4];
  10. int died=1;
  11. int diedLast;
  12. int i,j,k,l;
  13. int valid;
  14. int turn;
  15. int king1x, king1y, king2x, king2y;
  16. int checkWhite, checkBlack;
  17. int checkMateBlack,checkMateWhite;
  18.  
  19. void readLine()
  20. {
  21. int ch, i=0;
  22. while((ch=getchar()) != '\n'){
  23. if(i<4)
  24. {
  25. play[i++]=ch;
  26. }
  27. }
  28. play[i]='\0';
  29. }
  30.  
  31. void gameBoardBorders();
  32. void checkerBoard();
  33. void startingChessBoard();
  34. void printGame ();
  35. void scanAndConvert();
  36. void checkValidMove();
  37. void swapElements ();
  38. void reverseSwapElement();
  39. void rook();
  40. void knight();
  41. void king();
  42. void king();
  43. void bishop();
  44. void queen();
  45. void pawn();
  46. void moveSet();
  47. void fullKingCheckWhite(int x,int y);
  48. void fullKingCheckBlack(int x,int y);
  49. void kingWhiteCheckMate();
  50. void kingBlackCheckMate();
  51. void checkMateBlackPath(int x,int y);
  52. void checkMateWhitePath(int x,int y);
  53. void kingWhiteStaleMate();
  54. void kingBlackStaleMate();
  55. void fullPieceCheckBlack(int x,int y);
  56. void fullPieceCheckWhite(int x,int y);
  57.  
  58. int main(){
  59. startingChessBoard();
  60. gameBoardBorders();
  61. checkerBoard();
  62. printGame();
  63. king1x=9, king1y=6, king2x=2, king2y=6;
  64. turn=1;
  65. diedLast=0;
  66. checkWhite=0;
  67. checkBlack=0;
  68. while (1){
  69. valid = 0;
  70. checkMateBlack=-1;checkMateWhite=-1;
  71. if (turn==1){
  72. while ((valid==0)||(checkWhite==1)){
  73. printf("\nWhite's turn: ");
  74. scanAndConvert();
  75. if(valid==1){
  76. checkValidMove();
  77. }
  78. if(valid==1){
  79. moveSet();
  80. }
  81. if (valid==1){
  82. swapElements();
  83. }
  84. if(valid==1){
  85. fullKingCheckWhite(king1x,king1y);
  86. }
  87. if ((valid==1)&&(checkWhite==1)){
  88. printf("Invalid move.");
  89. reverseSwapElement();
  90. }
  91. }
  92. printf("\n");
  93. printGame();
  94. kingWhiteStaleMate();
  95. if (checkMateBlack==0){
  96. printf("Stalemate.\n");
  97. exit(EXIT_SUCCESS);
  98. }
  99. fullKingCheckBlack(king2x,king2y);
  100. if (checkMateBlack==1){
  101. kingBlackCheckMate();
  102. if (checkMateWhite==0){
  103. printf("Check mate.\n");
  104. exit(EXIT_SUCCESS);
  105. }
  106. }
  107. fullKingCheckBlack(king2x,king2y);
  108. if (checkBlack==0){
  109. kingBlackStaleMate();
  110. if (checkMateWhite==0){
  111. printf("Stalemate.\n");
  112. exit(EXIT_SUCCESS);
  113. }
  114. }
  115. fullKingCheckBlack(king2x,king2y);
  116. if (checkBlack==1){
  117. printf("Check black.\n");
  118. }
  119. turn=2;
  120. }
  121. else {
  122. while ((valid==0)||(checkBlack==1)){
  123. printf("\nBlack's turn: ");
  124. scanAndConvert();
  125. if(valid==1){
  126. checkValidMove();
  127. }
  128. if(valid==1){
  129. moveSet();
  130. }
  131. if(valid==1){
  132. swapElements();
  133. }
  134. if(valid==1){
  135. fullKingCheckBlack(king2x,king2y);
  136. }
  137. if(checkBlack==1 && valid==1){
  138. printf("Invalid move.");
  139. reverseSwapElement();
  140. }
  141. }
  142. printf("\n");
  143. printGame();
  144. kingBlackStaleMate();
  145. if (checkMateWhite==0){
  146. printf("Stalemate.\n");
  147. exit(EXIT_SUCCESS);
  148. }
  149. fullKingCheckWhite(king1x,king1y);
  150. if (checkMateWhite==1){
  151. kingWhiteCheckMate();
  152. if (checkMateBlack==0){
  153. printf("Check mate.\n");
  154. exit(EXIT_SUCCESS);
  155. }
  156. }
  157. fullKingCheckWhite(king1x,king1y);
  158. if (checkWhite==0){
  159. kingWhiteStaleMate();
  160. if (checkMateBlack==0){
  161. printf("Stalemate.\n");
  162. exit(EXIT_SUCCESS);
  163. }
  164. }
  165. fullKingCheckWhite(king1x,king1y);
  166. if (checkWhite==1){
  167. printf("Check white.\n");
  168. }
  169. turn=1;
  170. }
  171. }
  172. return 0;
  173. }
  174.  
  175. void gameBoardBorders(){
  176. for (i=0;i<12;i++){
  177. for (j=0;j<12;j++){
  178. gameBoard[i][j]='\0';
  179. }
  180. }
  181. for (i=0;i<12;i+=11){
  182. for (j=2;j<10;j++){
  183. gameBoard[i][j]='A'+(j-2);
  184. }
  185. }
  186. for (j=2;j<10;j++){
  187. gameBoard[1][j]='-';
  188. gameBoard[10][j]='-';
  189. }
  190. for (i=2;i<10;i++){
  191. for (j=0;j<12;j+=11){
  192. gameBoard[i][j]='8'-(i-2);
  193. }
  194. }
  195. for (i=2;i<10;i++){
  196. gameBoard[i][1]='|';
  197. gameBoard[i][10]='|';
  198. }
  199.  
  200. }
  201.  
  202. void checkerBoard(){
  203. for (i=2;i<10;i++){
  204. for (j=2;j<10;j+=2){
  205. if (i%2==0){
  206. gameBoard[i][j]='.';
  207. }
  208. else {
  209. gameBoard[i][j]='_';
  210. }
  211. }
  212. }
  213. for (i=2;i<10;i++){
  214. for (j=3;j<10;j+=2){
  215. if (i%2==0){
  216. gameBoard[i][j]='_';
  217. }
  218. else {
  219. gameBoard[i][j]='.';
  220. }
  221. }
  222. }
  223. }
  224.  
  225. void startingChessBoard(){
  226. for (i=0;i<12;i++){
  227. for(j=0;j<12;j++){
  228. pieces[i][j]='\0';
  229. }
  230. }
  231. pieces[2][2]= 'R';
  232. pieces[2][3]= 'N';
  233. pieces[2][4]= 'B';
  234. pieces[2][5]= 'Q';
  235. pieces[2][6]= 'K';
  236. pieces[2][7]= 'B';
  237. pieces[2][8]= 'N';
  238. pieces[2][9]= 'R';
  239.  
  240. pieces[9][2]= 'r';
  241. pieces[9][3]= 'n';
  242. pieces[9][4]= 'b';
  243. pieces[9][5]= 'q';
  244. pieces[9][6]= 'k';
  245. pieces[9][7]= 'b';
  246. pieces[9][8]= 'n';
  247. pieces[9][9]= 'r';
  248.  
  249. for(j=2;j<10;j++){
  250. pieces[3][j]= 'P';
  251. }
  252.  
  253. for(j=2;j<10;j++){
  254. pieces[8][j]= 'p';
  255. }
  256. for(i=0;i<36;i++){
  257. deadPieces[i]='\0';
  258. }
  259. }
  260.  
  261. void printGame (){
  262. system("cls");
  263. printf("\n\t\t\t\t\t\tDead\n\n");
  264. for (i=0;i<12;i++){
  265. for (j=0;j<12;j++){
  266. printf("%c",gameBoard[i][j]);
  267. printf("%c ", pieces[i][j]);
  268. }
  269. printf("\t\t%c %c %c", deadPieces[i+1], deadPieces[i+13], deadPieces[i+25]);
  270. printf("\n\n");
  271. }
  272. printf("\n");
  273. }
  274.  
  275. void scanAndConvert(){
  276. readLine();
  277. while (play[4]!='\0'){
  278. printf("Invalid move.");
  279. valid=0;
  280. return;
  281. }
  282. while ((play[0]<'A')||(play[0]>'H')||(play[1]<'1')||(play[1]>'8')||(play[2]<'A')||(play[2]>'H')||(play[3]<'1')||(play[3]>'8')){
  283. printf("Invalid move.");
  284. valid=0;
  285. return;
  286. }
  287. index[0]=58-play[1];
  288. index[1]=play[0]-63;
  289. index[2]=58-play[3];
  290. index[3]=play[2]-63;
  291. valid=1;
  292. }
  293.  
  294. void checkValidMove(){
  295. if (turn==1){
  296. if ((pieces[index[0]][index[1]]<'a')||(pieces[index[0]][index[1]]>'z')){
  297. printf("Invalid move.");
  298. valid=0;
  299. return;
  300. }
  301. if ((pieces[index[2]][index[3]]>='a')&&(pieces[index[2]][index[3]]<='z')){
  302. printf("Invalid move.");
  303. valid=0;
  304. return;
  305. }
  306. }
  307. else if (turn==2){
  308. if ((pieces[index[0]][index[1]]<'A')||(pieces[index[0]][index[1]]>'Z')){
  309. printf("Invalid move.");
  310. valid=0;
  311. return;
  312. }
  313. if((pieces[index[2]][index[3]]>='A')&&(pieces[index[2]][index[3]]<='Z')){
  314. printf("Invalid move.");
  315. valid=0;
  316. return;
  317. }
  318. }
  319. valid=1;
  320. }
  321.  
  322. void swapElements (){
  323. if ((pieces[index[2]][index[3]])!='\0'){
  324. deadPieces[died]= pieces[index[2]][index[3]];
  325. died++;
  326. pieces[index[2]][index[3]]='\0';
  327. diedLast=1;
  328. }else{
  329. diedLast=0;
  330. }
  331. char temp=pieces[index[0]][index[1]];
  332. pieces[index[0]][index[1]]=pieces[index[2]][index[3]];
  333. pieces[index[2]][index[3]]=temp;
  334. }
  335.  
  336. void reverseSwapElement(){
  337. if(diedLast==1){
  338. if(pieces[index[0]][index[1]]=='\0' || deadPieces[died-1]!='\0'){
  339. pieces[index[0]][index[1]]=deadPieces[died-1];
  340. died--;
  341. deadPieces[died]='\0';
  342. }
  343. }
  344. char temp=pieces[index[2]][index[3]];
  345. pieces[index[2]][index[3]]=pieces[index[0]][index[1]];
  346. pieces[index[0]][index[1]]=temp;
  347. }
  348.  
  349. void rook(){
  350. if((index[3]-index[1])==0 && (index[2]-index[0]>0)){
  351. for (i=1;i<index[2]-index[0];i++){
  352. if (pieces[index[0]+i][index[1]]!='\0'){
  353. printf("Invalid move.");
  354. valid=0;
  355. return;
  356. }
  357. }
  358. if(index[0]+i==index[2]){
  359. valid=1;
  360. }
  361. }
  362. else if ((index[3]-index[1])==0 && (index[0]-index[2]>0)){
  363. for (i=1;i<index[0]-index[2];i++){
  364. if (pieces[index[0]-i][index[1]]!='\0'){
  365. printf("Invalid move.");
  366. valid=0;
  367. return;
  368. }
  369. }
  370. if (index[0]-i==index[2]){
  371. valid=1;
  372. }
  373. }
  374. else if ((index[3]-index[1])>0 && (index[2]-index[0]==0)){
  375. for (i=1;i<index[3]-index[1];i++){
  376. if (pieces[index[0]][index[1]+i]!='\0'){
  377. printf("Invalid move.");
  378. valid=0;
  379. return;
  380. }
  381. }
  382. if(index[1]+i==index[3]){
  383. valid=1;
  384. }
  385. }
  386. else if ((index[1]-index[3])>0 && (index[2]-index[0]==0)){
  387. for (i=1;i<index[1]-index[3];i++){
  388. if (pieces[index[0]][index[1]-i]!='\0'){
  389. printf("Invalid move.");
  390. valid=0;
  391. return;
  392. }
  393. }
  394. if(index[1]-i==index[3]){
  395. valid=1;
  396. }
  397. }
  398. else{
  399. printf("Invalid move.");
  400. valid=0;
  401. return;
  402. }
  403. }
  404.  
  405. void knight(){
  406. if ((((abs(index[3]-index[1]))==1)&&((abs(index[2]-index[0]))==2)) || (((abs(index[3]-index[1]))==2)&&((abs(index[2]-index[0]))==1)))
  407. {
  408. valid=1;
  409. }else{
  410. printf("Invalid move.");
  411. valid=0;
  412. return;
  413. }
  414. }
  415.  
  416. void king(){
  417. if((((abs(index[3]-index[1]))==1) && ((abs(index[2]-index[0]))==1)) || (((abs(index[3]-index[1]))==1) && ((abs(index[2]-index[0]))==0)) || (((abs(index[3]-index[1]))==0) && ((abs(index[2]-index[0]))==1)))
  418. {
  419. if (turn==1){
  420. king1x=index[2];
  421. king1y=index[3];
  422. }
  423. else{
  424. king2x=index[2];
  425. king2y=index[3];
  426. }
  427. valid=1;
  428. }else{
  429. printf("Invalid move.");
  430. valid=0;
  431. return;
  432. }
  433. }
  434.  
  435. void bishop(){
  436. if (((index[0]-index[2])==(index[1]-index[3]))&&((index[0]-index[2])>0)){
  437. for (i=1;i<index[0]-index[2];i++){
  438. if ((pieces[index[0]-i][index[1]-i])!='\0'){
  439. printf("Invalid move.");
  440. valid=0;
  441. return;
  442. }
  443. }
  444. if ((index[0]-i==index[2])&&(index[1]-i==index[3])){
  445. valid=1;
  446. }
  447. }
  448. else if (((index[0]-index[2])==(index[1]-index[3]))&&((index[2]-index[0])>0)){
  449. for (i=1;i<index[2]-index[0];i++){
  450. if ((pieces[index[0]+i][index[1]+i])!='\0'){
  451. printf("Invalid move.");
  452. valid=0;
  453. return;
  454. }
  455. }
  456. if ((index[0]+i==index[2])&&(index[1]+i==index[3])){
  457. valid=1;
  458. }
  459. }
  460. else if (((index[0]-index[2])==(index[3]-index[1]))&&((index[0]-index[2])>0)){
  461. for (i=1;i<index[0]-index[2];i++){
  462. if ((pieces[index[0]-i][index[1]+i])!='\0'){
  463. printf("Invalid move.");
  464. valid=0;
  465. return;
  466. }
  467. }
  468. if ((index[0]-i==index[2])&&(index[1]+i==index[3])){
  469. valid=1;
  470. }
  471. }
  472. else if (((index[0]-index[2])==(index[3]-index[1]))&&((index[2]-index[0])>0)){
  473. for (i=1;i<index[0]-index[2];i++){
  474. if ((pieces[index[0]+i][index[1]-i])!='\0'){
  475. printf("Invalid move.");
  476. valid=0;
  477. return;
  478. }
  479. }
  480. if ((index[0]+i==index[2])&&(index[1]-i==index[3])){
  481. valid=1;
  482. }
  483. }
  484. else{
  485. printf("Invalid move.");
  486. valid=0;
  487. return;
  488. }
  489. }
  490.  
  491. void queen(){
  492. if((index[3]-index[1])==0 && (index[2]-index[0]>0)){
  493. for (i=1;i<index[2]-index[0];i++){
  494. if (pieces[index[0]+i][index[1]]!='\0'){
  495. printf("Invalid move.");
  496. valid=0;
  497. return;
  498. }
  499. }
  500. if(index[0]+i==index[2]){
  501. valid=1;
  502. }
  503. }
  504. else if ((index[3]-index[1])==0 && (index[0]-index[2]>0)){
  505. for (i=1;i<index[0]-index[2];i++){
  506. if (pieces[index[0]-i][index[1]]!='\0'){
  507. printf("Invalid move.");
  508. valid=0;
  509. return;
  510. }
  511. }
  512. if (index[0]-i==index[2]){
  513. valid=1;
  514. }
  515. }
  516. else if ((index[3]-index[1])>0 && (index[2]-index[0]==0)){
  517. for (i=1;i<index[3]-index[1];i++){
  518. if (pieces[index[0]][index[1]+i]!='\0'){
  519. printf("Invalid move.");
  520. valid=0;
  521. return;
  522. }
  523. }
  524. if(index[1]+i==index[3]){
  525. valid=1;
  526. }
  527. }
  528. else if ((index[1]-index[3])>0 && (index[2]-index[0]==0)){
  529. for (i=1;i<index[1]-index[3];i++){
  530. if (pieces[index[0]][index[1]-i]!='\0'){
  531. printf("Invalid move.");
  532. valid=0;
  533. return;
  534. }
  535. }
  536. if(index[1]-i==index[3]){
  537. valid=1;
  538. }
  539. }
  540. else if (((index[0]-index[2])==(index[1]-index[3]))&&((index[0]-index[2])>0)){
  541. for (i=1;i<index[0]-index[2];i++){
  542. if ((pieces[index[0]-i][index[1]-i])!='\0'){
  543. printf("Invalid move.");
  544. valid=0;
  545. return;
  546. }
  547. }
  548. if ((index[0]-i==index[2])&&(index[1]-i==index[3])){
  549. valid=1;
  550. }
  551. }
  552. else if (((index[0]-index[2])==(index[1]-index[3]))&&((index[2]-index[0])>0)){
  553. for (i=1;i<index[2]-index[0];i++){
  554. if ((pieces[index[0]+i][index[1]+i])!='\0'){
  555. printf("Invalid move.");
  556. valid=0;
  557. return;
  558. }
  559. }
  560. if ((index[0]+i==index[2])&&(index[1]+i==index[3])){
  561. valid=1;
  562. }
  563. }
  564. else if (((index[0]-index[2])==(index[3]-index[1]))&&((index[0]-index[2])>0)){
  565. for (i=1;i<index[0]-index[2];i++){
  566. if ((pieces[index[0]-i][index[1]+i])!='\0'){
  567. printf("Invalid move.");
  568. valid=0;
  569. return;
  570. }
  571. }
  572. if ((index[0]-i==index[2])&&(index[1]+i==index[3])){
  573. valid=1;
  574. }
  575. }
  576. else if (((index[0]-index[2])==(index[3]-index[1]))&&((index[2]-index[0])>0)){
  577. for (i=1;i<index[0]-index[2];i++){
  578. if ((pieces[index[0]+i][index[1]-i])!='\0'){
  579. printf("Invalid move.");
  580. valid=0;
  581. return;
  582. }
  583. }
  584. if ((index[0]+i==index[2])&&(index[1]-i==index[3])){
  585. valid=1;
  586. }
  587. }
  588. else{
  589. printf("Invalid move.");
  590. valid=0;
  591. return;
  592. }
  593. }
  594.  
  595. void pawn(){
  596. char promote;
  597. if (pieces[index[0]][index[1]]=='p'){
  598. if(index[0]==8){
  599. if(((index[2]-index[0]==-1)||(index[2]-index[0]==-2)) && (index[3]-index[1]==0) && (pieces[index[2]][index[3]]=='\0')){
  600. valid = 1;
  601. }
  602. else if((pieces[index[2]][index[3]]!='\0')&& ((index[2]-index[0]==-1)&& (abs(index[3]-index[1])==1))){
  603. valid = 1;
  604. }
  605. else if ((pieces[index[2]][index[3]]!='\0')&& ((index[2]-index[0]==-1)&& (abs(index[3]-index[1])==1))){
  606. valid=1;
  607. }
  608. else{
  609. printf("Invalid move.");
  610. valid=0;
  611. return;
  612. }
  613. }else{
  614. if((index[2]-index[0]==-1) && (index[3]-index[1]==0) && (pieces[index[2]][index[3]]=='\0')){
  615. valid = 1;
  616. }
  617. else if((pieces[index[2]][index[3]]!='\0')&& ((index[2]-index[0]==-1)&& (abs(index[3]-index[1])==1))){
  618. valid = 1;
  619. }
  620. else{
  621. printf("Invalid move.");
  622. valid=0;
  623. return;
  624. }
  625. }
  626. if (index[2]==2){
  627. printf("Promote to: ");
  628. scanf(" %c", &promote);
  629. while(promote != 'R' && promote != 'N' && promote != 'B' && promote != 'Q' && promote != 'P'){
  630. printf("Wrong promotion\n");
  631. printf("Promote to: ");
  632. scanf(" %c", &promote);
  633. }
  634. if(promote == 'R'){
  635. pieces[index[0]][index[1]]='r';
  636. valid=1;
  637. }
  638. else if(promote == 'N'){
  639. pieces[index[0]][index[1]]='n';
  640. valid=1;
  641. }
  642. else if(promote == 'B'){
  643. pieces[index[0]][index[1]]='b';
  644. valid=1;
  645. }
  646. else if(promote == 'Q'){
  647. pieces[index[0]][index[1]]='q';
  648. valid=1;
  649. }else if(promote == 'P'){
  650. pieces[index[0]][index[1]]='p';
  651. valid=1;
  652. }
  653. }
  654. }
  655. else{
  656. if(index[0]==3){
  657. if(((index[2]-index[0]==1)||(index[2]-index[0]==2)) && (index[3]-index[1]==0) && (pieces[index[2]][index[3]]=='\0')){
  658. valid = 1;
  659. }
  660. else if((pieces[index[2]][index[3]]!='\0')&& ((index[2]-index[0]==-1)&& (abs(index[3]-index[1])==1))){
  661. valid = 1;
  662. }
  663. else if ((pieces[index[2]][index[3]]!='\0')&& ((index[2]-index[0]==1)&& (abs(index[3]-index[1])==1))){
  664. valid=1;
  665. }
  666. else{
  667. printf("Invalid move.");
  668. valid=0;
  669. return;
  670. }
  671. }else{
  672. if((index[2]-index[0]==1) && (index[3]-index[1]==0) && (pieces[index[2]][index[3]]=='\0')){
  673. valid = 1;
  674. }
  675. else if((pieces[index[2]][index[3]]!='\0')&& ((index[2]-index[0]==1)&& (abs(index[3]-index[1])==1))){
  676. valid = 1;
  677. }
  678. else{
  679. printf("Invalid move.");
  680. valid=0;
  681. return;
  682. }
  683. }
  684. if (index[2]==9){
  685. printf("Promote to: ");
  686. scanf(" %c", &promote);
  687. while(promote != 'R' && promote != 'N' && promote != 'B' && promote != 'Q' && promote != 'P' ){
  688. printf("Wrong promotion\n");
  689. printf("Promote to: ");
  690. scanf(" %c", &promote);
  691. }
  692. if(promote == 'R'){
  693. pieces[index[0]][index[1]]='R';
  694. valid=1;
  695. }
  696. else if(promote == 'N'){
  697. pieces[index[0]][index[1]]='N';
  698. valid=1;
  699. }
  700. else if(promote == 'B'){
  701. pieces[index[0]][index[1]]='B';
  702. valid=1;
  703. }
  704. else if(promote == 'Q'){
  705. pieces[index[0]][index[1]]='Q';
  706. valid=1;
  707. }else if(promote == 'P'){
  708. pieces[index[0]][index[1]]='P';
  709. valid=1;
  710. }
  711. }
  712. }
  713. }
  714.  
  715. void moveSet(){
  716. if ((pieces[index[0]][index[1]]=='p')||(pieces[index[0]][index[1]]=='P')){
  717. pawn();
  718. }
  719. else if ((pieces[index[0]][index[1]]=='r')||(pieces[index[0]][index[1]]=='R')){
  720. rook();
  721. }
  722. else if ((pieces[index[0]][index[1]]=='n')||(pieces[index[0]][index[1]]=='N')){
  723. knight();
  724. }
  725. else if ((pieces[index[0]][index[1]]=='b')||(pieces[index[0]][index[1]]=='B')){
  726. bishop();
  727. }
  728. else if ((pieces[index[0]][index[1]]=='q')||(pieces[index[0]][index[1]]=='Q')){
  729. queen();
  730. }
  731. else if ((pieces[index[0]][index[1]]=='k')||(pieces[index[0]][index[1]]=='K')){
  732. king();
  733. }
  734. }
  735.  
  736.  
  737. void fullKingCheckWhite(int x,int y){
  738. if ((pieces[x-1][y+2]=='N')||(pieces[x+1][y+2]=='N')||(pieces[x-1][y-2]=='N')||(pieces[x+1][y-2]=='N')||(pieces[x+2][y-1]=='N')||(pieces[x+2][y+1]=='N')||(pieces[x-2][y-1]=='N')||(pieces[x-2][y+1]=='N')){
  739. checkWhite=1;
  740. checkMateWhite=1;
  741. return;
  742. }
  743. else if ((pieces[x-1][y-1]=='P')||(pieces[x-1][y+1]=='P')){
  744. checkWhite=1;
  745. checkMateWhite=1;
  746. return;
  747. }
  748. else if ((pieces[x-1][y]=='P')&&(pieces[x][y]=='\0')){
  749. checkWhite=1;
  750. checkMateWhite=1;
  751. return;
  752. }
  753. else if ((pieces[x+1][y]=='K')||(pieces[x-1][y]=='K')||(pieces[x][y+1]=='K')||(pieces[x][y-1]=='K')||(pieces[x+1][y+1]=='K')||(pieces[x-1][y-1]=='K')||(pieces[x+1][y-1]=='K')||(pieces[x-1][y+1]=='K')){
  754. checkWhite=1;
  755. checkMateWhite=1;
  756. return;
  757. }
  758. else{
  759. for(i=1; i<=7;i++){
  760. if(x+i>9){
  761. break;
  762. }
  763. else if(pieces[x+i][y]!='\0' && (pieces[x+i][y]!='R' && pieces[x+i][y]!='Q')){
  764. checkWhite=0;
  765. checkMateWhite=0;
  766. break;
  767. }
  768. else if(pieces[x+i][y]=='R'||pieces[x+i][y]=='Q'){
  769. checkWhite=1;
  770. checkMateWhite=1;
  771. return;
  772. }
  773. }
  774. for(i=1; i<=7;i++){
  775. if(x-i<2){
  776. break;
  777. }
  778. else if(pieces[x-i][y]!='\0' && (pieces[x-i][y]!='R' && pieces[x-i][y]!='Q')){
  779. checkWhite=0;
  780. checkMateWhite=0;
  781. break;
  782. }
  783. else if(pieces[x-i][y]=='R'||pieces[x-i][y]=='Q'){
  784. checkWhite=1;
  785. checkMateWhite=1;
  786. return;
  787. }
  788. }
  789. for(i=1; i<=7;i++){
  790. if(y+i>9){
  791. break;
  792. }
  793. else if(pieces[x][y+i]!='\0' && (pieces[x][y+i]!='R' && pieces[x][y+i]!='Q')){
  794. checkWhite=0;
  795. checkMateWhite=0;
  796. break;
  797. }
  798. else if(pieces[x][y+i]=='R'||pieces[x][y+i]=='Q'){
  799. checkWhite=1;
  800. checkMateWhite=1;
  801. return;
  802. }
  803. }
  804. for(i=1; i<=7;i++){
  805. if(y-i<2){
  806. break;
  807. }
  808. else if(pieces[x][y-i]!='\0' && (pieces[x][y-i]!='R' && pieces[x][y-i]!='Q')){
  809. checkWhite=0;
  810. checkMateWhite=0;
  811. break;
  812. }
  813. else if(pieces[x][y-i]=='R'||pieces[x][y-i]=='Q'){
  814. checkWhite=1;
  815. checkMateWhite=1;
  816. return;
  817. }
  818. }
  819. for(i=1; i<=7;i++){
  820. if(x+i>9 && y+i>9){
  821. break;
  822. }else if(pieces[x+i][y+i]!='\0' && (pieces[x+i][y+i]!='B' && pieces[x+i][y+i]!='Q')){
  823. checkWhite=0;
  824. checkMateWhite=0;
  825. break;
  826. }
  827. else if(pieces[x+i][y+i]=='B'||pieces[x+i][y+i]=='Q'){
  828. checkWhite=1;
  829. checkMateWhite=1;
  830. return;
  831. }
  832. }
  833. for(i=1; i<=7;i++){
  834. if(x-i<2 && y+i>9){
  835. break;
  836. }else if(pieces[x-i][y+i]!='\0' && (pieces[x-i][y+i]!='B' && pieces[x-i][y+i]!='Q')){
  837. checkWhite=0;
  838. checkMateWhite=0;
  839. break;
  840. }
  841. else if(pieces[x-i][y+i]=='B'||pieces[x-i][y+i]=='Q'){
  842. checkWhite=1;
  843. checkMateWhite=1;
  844. return;
  845. }
  846. }
  847. for(i=1; i<=7;i++){
  848. if(x-i<2 && y-i<2){
  849. break;
  850. }else if(pieces[x-i][y-i]!='\0' && (pieces[x-i][y-i]!='B' && pieces[x-i][y-i]!='Q')){
  851. checkWhite=0;
  852. checkMateWhite=0;
  853. break;
  854. }
  855. else if(pieces[x-i][y-i]=='B'||pieces[x-i][y-i]=='Q'){
  856. checkWhite=1;
  857. checkMateWhite=1;
  858. return;
  859. }
  860. }
  861. for(i=1; i<=7;i++){
  862. if(x+i>9 && y-i<2){
  863. break;
  864. }else if(pieces[x+i][y-i]!='\0' && (pieces[x+i][y-i]!='B' && pieces[x+i][y-i]!='Q')){
  865. checkWhite=0;
  866. checkMateWhite=0;
  867. break;
  868. }
  869. else if(pieces[x+i][y-i]=='B'||pieces[x+i][y-i]=='Q'){
  870. checkWhite=1;
  871. checkMateWhite=1;
  872. return;
  873. }
  874. }
  875. }
  876. }
  877.  
  878. void fullKingCheckBlack(int x,int y){
  879. if ((pieces[x-1][y+2]=='n')||(pieces[x+1][y+2]=='n')||(pieces[x-1][y-2]=='n')||(pieces[x+1][y-2]=='n')||(pieces[x+2][y-1]=='n')||(pieces[x+2][y+1]=='n')||(pieces[x-2][y-1]=='n')||(pieces[x-2][y+1]=='n')){
  880. checkBlack=1;
  881. checkMateBlack=1;
  882. return;
  883. }
  884. else if ((pieces[x+1][y-1]=='p')||(pieces[x+1][y+1]=='p')){
  885. checkBlack=1;
  886. checkMateBlack=1;
  887. return;
  888. }
  889. else if ((pieces[x+1][y]=='k')||(pieces[x-1][y]=='k')||(pieces[x][y+1]=='k')||(pieces[x][y-1]=='k')||(pieces[x+1][y+1]=='k')||(pieces[x-1][y-1]=='k')||(pieces[x+1][y-1]=='k')||(pieces[x-1][y+1]=='k')){
  890. checkBlack=1;
  891. checkMateBlack=1;
  892. return;
  893. }
  894. else{
  895. for(i=1; i<=7;i++){
  896. if(x+i>9){
  897. break;
  898. }
  899. else if(pieces[x+i][y]!='\0' && (pieces[x+i][y]!='r' && pieces[x+i][y]!='q')){
  900. checkBlack=0;
  901. checkMateBlack=0;
  902. break;
  903. }
  904. else if(pieces[x+i][y]=='r'||pieces[x+i][y]=='q'){
  905. checkBlack=1;
  906. checkMateBlack=1;
  907. return;
  908. }
  909. }
  910. for(i=1; i<=7;i++){
  911. if(x-i<2){
  912. break;
  913. }
  914. else if(pieces[x-i][y]!='\0' && (pieces[x-i][y]!='r' && pieces[x-i][y]!='q')){
  915. checkBlack=0;
  916. checkMateBlack=0;
  917. break;
  918. }
  919. else if(pieces[x-i][y]=='r'||pieces[x-i][y]=='q'){
  920. checkBlack=1;
  921. checkMateBlack=1;
  922. return;
  923. }
  924. }
  925. for(i=1; i<=7;i++){
  926. if(y+i>9){
  927. break;
  928. }
  929. else if(pieces[x][y+i]!='\0' && (pieces[x][y+i]!='r' && pieces[x][y+i]!='q')){
  930. checkBlack=0;
  931. checkMateBlack=0;
  932. break;
  933. }
  934. else if(pieces[x][y+i]=='r'||pieces[x][y+i]=='q'){
  935. checkBlack=1;
  936. checkMateBlack=1;
  937. return;
  938. }
  939. }
  940. for(i=1; i<=7;i++){
  941. if(y-i<2){
  942. break;
  943. }
  944. else if(pieces[x][y-i]!='\0' && (pieces[x][y-i]!='r' && pieces[x][y-i]!='q')){
  945. checkBlack=0;
  946. checkMateBlack=0;
  947. break;
  948. }
  949. else if(pieces[x][y-i]=='r'||pieces[x][y-i]=='q'){
  950. checkBlack=1;
  951. checkMateBlack=1;
  952. return;
  953. }
  954. }
  955. for(i=1; i<=7;i++){
  956. if(x+i>9 && y+i>9){
  957. break;
  958. }else if(pieces[x+i][y+i]!='\0' && (pieces[x+i][y+i]!='b' && pieces[x+i][y+i]!='q')){
  959. checkBlack=0;
  960. checkMateBlack=0;
  961. break;
  962. }
  963. else if(pieces[x+i][y+i]=='b'||pieces[x+i][y+i]=='q'){
  964. checkBlack=1;
  965. checkMateBlack=1;
  966. return;
  967. }
  968. }
  969. for(i=1; i<=7;i++){
  970. if(x-i<2 && y+i>9){
  971. break;
  972. }else if(pieces[x-i][y+i]!='\0' && (pieces[x-i][y+i]!='b' && pieces[x-i][y+i]!='q')){
  973. checkBlack=0;
  974. checkMateBlack=0;
  975. break;
  976. }
  977. else if(pieces[x-i][y+i]=='b'||pieces[x-i][y+i]=='q'){
  978. checkBlack=1;
  979. checkMateBlack=1;
  980. return;
  981. }
  982. }
  983. for(i=1; i<=7;i++){
  984. if(x-i<2 && y-i<2){
  985. break;
  986. }else if(pieces[x-i][y-i]!='\0' && (pieces[x-i][y-i]!='b' && pieces[x-i][y-i]!='q')){
  987. checkBlack=0;
  988. checkMateBlack=0;
  989. break;
  990. }
  991. else if(pieces[x-i][y-i]=='b'||pieces[x-i][y-i]=='q'){
  992. checkBlack=1;
  993. checkMateBlack=1;
  994. return;
  995. }
  996. }
  997. for(i=1; i<=7;i++){
  998. if(x+i>9 && y-i<2){
  999. break;
  1000. }else if(pieces[x+i][y-i]!='\0' && (pieces[x+i][y-i]!='b' && pieces[x+i][y-i]!='q')){
  1001. checkBlack=0;
  1002. checkMateBlack=0;
  1003. break;
  1004. }
  1005. else if(pieces[x+i][y-i]=='b'||pieces[x+i][y-i]=='q'){
  1006. checkBlack=1;
  1007. checkMateBlack=1;
  1008. return;
  1009. }
  1010. }
  1011. }
  1012. }
  1013.  
  1014. void kingWhiteCheckMate(){
  1015. checkMateWhite=1;
  1016. if ((pieces[king1x+1][king1y]<'a')&&(king1x+1>1)&&(king1x+1<10)){
  1017. fullKingCheckWhite(king1x+1,king1y);
  1018. }
  1019. if ((checkMateWhite==1)&&(pieces[king1x][king1y+1]<'a')&&(king1y+1>1)&&(king1y+1<10)){
  1020. fullKingCheckWhite(king1x,king1y+1);
  1021. }
  1022. if ((checkMateWhite==1)&&(pieces[king1x+1][king1y+1]<'a')&&(king1y+1>1)&&(king1y+1<10)&&(king1x+1>1)&&(king1x+1<10)){
  1023. fullKingCheckWhite(king1x+1,king1y+1);
  1024. }
  1025. if ((checkMateWhite==1)&&(pieces[king1x-1][king1y]<'a')&&(king1x-1>1)&&(king1x-1<10)){
  1026. fullKingCheckWhite(king1x-1,king1y);
  1027. }
  1028. if ((checkMateWhite==1)&&(pieces[king1x][king1y-1]<'a')&&(king1y-1>1)&&(king1y-1<10)){
  1029. fullKingCheckWhite(king1x,king1y-1);
  1030. }
  1031. if ((checkMateWhite==1)&&(pieces[king1x-1][king1y-1]<'a')&&(king1y-1>1)&&(king1y-1<10)&&(king1x-1>1)&&(king1x-1<10)){
  1032. fullKingCheckWhite(king1x-1,king1y-1);
  1033. }
  1034. if ((checkMateWhite==1)&&(pieces[king1x+1][king1y-1]<'a')&&(king1y-1>1)&&(king1y-1<10)&&(king1x+1>1)&&(king1x+1<10)){
  1035. fullKingCheckWhite(king1x+1,king1y-1);
  1036. }
  1037. if ((checkMateWhite==1)&&(pieces[king1x-1][king1y+1]<'a')&&(king1y+1>1)&&(king1y+1<10)&&(king1x-1>1)&&(king1x-1<10)){
  1038. fullKingCheckWhite(king1x-1,king1y+1);
  1039. }
  1040. if (checkMateWhite==1){
  1041. fullPieceCheckBlack(index[2],index[3]);
  1042. if (checkMateBlack==0){
  1043. checkMateBlackPath(king1x,king1y);
  1044. }
  1045. }
  1046. }
  1047.  
  1048. void kingBlackCheckMate(){
  1049. checkMateWhite=1;
  1050. if (((pieces[king2x+1][king2y]>='a')||(pieces[king2x+1][king2y]=='\0'))&&(king2x+1>1)&&(king2x+1<10)){
  1051. fullKingCheckBlack(king2x+1,king2y);
  1052. }
  1053. if ((checkMateBlack==1)&&((pieces[king2x][king2y+1]>='a')||(pieces[king2x][king2y+1]=='\0'))&&(king2y+1>1)&&(king2y+1<10)){
  1054. fullKingCheckBlack(king2x,king2y+1);
  1055. }
  1056. if ((checkMateBlack==1)&&((pieces[king2x+1][king2y+1]>='a')||(pieces[king2x+1][king2y+1]=='\0'))&&(king2y+1>1)&&(king2y+1<10)&&(king2x+1>1)&&(king2x+1<10)){
  1057. fullKingCheckBlack(king2x+1,king2y+1);
  1058. }
  1059. if ((checkMateBlack==1)&&((pieces[king2x-1][king2y]>='a')||(pieces[king2x-1][king2y]=='\0'))&&(king2x-1>1)&&(king2x-1<10)){
  1060. fullKingCheckBlack(king2x-1,king2y);
  1061. }
  1062. if ((checkMateBlack==1)&&((pieces[king2x][king2y-1]>='a')||(pieces[king2x][king2y-1]=='\0'))&&(king2y-1>1)&&(king2y-1<10)){
  1063. fullKingCheckBlack(king2x,king2y-1);
  1064. }
  1065. if ((checkMateBlack==1)&&((pieces[king2x-1][king2y-1]>='a')||(pieces[king2x-1][king2y-1]=='\0'))&&(king2y-1>1)&&(king2y-1<10)&&(king2x-1>1)&&(king2x-1<10)){
  1066. fullKingCheckBlack(king2x-1,king2y-1);
  1067. }
  1068. if ((checkMateBlack==1)&&((pieces[king2x+1][king2y-1]>='a')||(pieces[king2x+1][king2y-1]=='\0'))&&(king2y-1>1)&&(king2y-1<10)&&(king2x+1>1)&&(king2x+1<10)){
  1069. fullKingCheckBlack(king2x+1,king2y-1);
  1070. }
  1071. if ((checkMateBlack==1)&&((pieces[king2x-1][king2y+1]>='a')||(pieces[king2x-1][king2y+1]=='\0'))&&(king2y+1>1)&&(king2y+1<10)&&(king2x-1>1)&&(king2x-1<10)){
  1072. fullKingCheckBlack(king2x-1,king2y+1);
  1073. }
  1074. if (checkMateBlack==1){
  1075. fullPieceCheckWhite(index[2],index[3]);
  1076. if (checkMateWhite==0){
  1077. checkMateWhitePath(king2x,king2y);
  1078. }
  1079. }
  1080. }
  1081.  
  1082. void checkMateWhitePath(int x,int y){
  1083. if((index[3]-y)==0 && (index[2]-x>0)){
  1084. for (k=1;k<index[2]-x;k++){
  1085. fullKingCheckBlack(x+k,y);
  1086. if (checkMateBlack==1){
  1087. break;
  1088. }
  1089. }
  1090. }
  1091. else if ((index[3]-y)==0 && (x-index[2]>0)){
  1092. for (k=1;k<x-index[2];k++){
  1093. fullKingCheckBlack(x-k,y);
  1094. if (checkMateBlack==1){
  1095. break;
  1096. }
  1097. }
  1098. }
  1099. else if ((index[3]-y)>0 && (index[2]-x==0)){
  1100. for (k=1;k<index[3]-y;k++){
  1101. fullKingCheckBlack(x,y+k);
  1102. if (checkMateBlack==1){
  1103. break;
  1104. }
  1105. }
  1106. }
  1107. else if ((y-index[3])>0 && (index[2]-x==0)){
  1108. for (k=1;k<y-index[3];k++){
  1109. fullKingCheckBlack(x,y-k);
  1110. if (checkMateBlack==1){
  1111. break;
  1112. }
  1113. }
  1114. }
  1115. else if (((x-index[2])==(y-index[3]))&&((x-index[2])>0)){
  1116. for (k=1;k<x-index[2];k++){
  1117. fullKingCheckBlack(x-k,y-k);
  1118. if (checkMateBlack==1){
  1119. break;
  1120. }
  1121. }
  1122. }
  1123. else if (((x-index[2])==(y-index[3]))&&((index[2]-x)>0)){
  1124. for (k=1;k<index[2]-x;k++){
  1125. fullKingCheckBlack(x+k,y+k);
  1126. if (checkMateBlack==1){
  1127. break;
  1128. }
  1129. }
  1130. }
  1131. else if (((x-index[2])==(index[3]-y))&&((x-index[2])>0)){
  1132. for (k=1;k<x-index[2];k++){
  1133. fullKingCheckBlack(x-k,y+k);
  1134. if (checkMateBlack==1){
  1135. break;
  1136. }
  1137. }
  1138. }
  1139. else if (((x-index[2])==(index[3]-y))&&((index[2]-x)>0)){
  1140. for (k=1;k<index[0]-index[2];k++){
  1141. fullKingCheckBlack(x+k,y-k);
  1142. if (checkMateBlack==1){
  1143. break;
  1144. }
  1145. }
  1146. }
  1147. }
  1148.  
  1149. void checkMateBlackPath(int x,int y){
  1150. if((index[3]-y)==0 && (index[2]-x>0)){
  1151. for (k=1;k<index[2]-x;k++){
  1152. fullKingCheckBlack(x+k,y);
  1153. if (checkMateBlack==1){
  1154. break;
  1155. }
  1156. }
  1157. }
  1158. else if ((index[3]-y)==0 && (x-index[2]>0)){
  1159. for (k=1;k<x-index[2];k++){
  1160. fullKingCheckBlack(x-k,y);
  1161. if (checkMateBlack==1){
  1162. break;
  1163. }
  1164. }
  1165. }
  1166. else if ((index[3]-y)>0 && (index[2]-x==0)){
  1167. for (k=1;k<index[3]-y;k++){
  1168. fullKingCheckBlack(x,y+k);
  1169. if (checkMateBlack==1){
  1170. break;
  1171. }
  1172. }
  1173. }
  1174. else if ((y-index[3])>0 && (index[2]-x==0)){
  1175. for (k=1;k<y-index[3];k++){
  1176. fullKingCheckBlack(x,y-k);
  1177. if (checkMateBlack==1){
  1178. break;
  1179. }
  1180. }
  1181. }
  1182. else if (((x-index[2])==(y-index[3]))&&((x-index[2])>0)){
  1183. for (k=1;k<x-index[2];k++){
  1184. fullKingCheckBlack(x-k,y-k);
  1185. if (checkMateBlack==1){
  1186. break;
  1187. }
  1188. }
  1189. }
  1190. else if (((x-index[2])==(y-index[3]))&&((index[2]-x)>0)){
  1191. for (k=1;k<index[2]-x;k++){
  1192. fullKingCheckBlack(x+k,y+k);
  1193. if (checkMateBlack==1){
  1194. break;
  1195. }
  1196. }
  1197. }
  1198. else if (((x-index[2])==(index[3]-y))&&((x-index[2])>0)){
  1199. for (k=1;k<x-index[2];k++){
  1200. fullKingCheckBlack(x-k,y+k);
  1201. if (checkMateBlack==1){
  1202. break;
  1203. }
  1204. }
  1205. }
  1206. else if (((x-index[2])==(index[3]-y))&&((index[2]-x)>0)){
  1207. for (k=1;k<index[0]-index[2];k++){
  1208. fullKingCheckBlack(x+k,y-k);
  1209. if (checkMateBlack==1){
  1210. break;
  1211. }
  1212. }
  1213. }
  1214. }
  1215.  
  1216. void kingWhiteStaleMate(){
  1217. checkWhite=1;
  1218. checkMateBlack=1;
  1219. if ((pieces[king1x+1][king1y]<'a')&&(king1x+1>1)&&(king1x+1<10)){
  1220. fullKingCheckWhite(king1x+1,king1y);
  1221. }
  1222. if ((checkWhite==1)&&(pieces[king1x][king1y+1]<'a')&&(king1y+1>1)&&(king1y+1<10)){
  1223. fullKingCheckWhite(king1x,king1y+1);
  1224. }
  1225. if ((checkWhite==1)&&(pieces[king1x+1][king1y+1]<'a')&&(king1y+1>1)&&(king1y+1<10)&&(king1x+1>1)&&(king1x+1<10)){
  1226. fullKingCheckWhite(king1x+1,king1y+1);
  1227. }
  1228. if ((checkWhite==1)&&(pieces[king1x-1][king1y]<'a')&&(king1x-1>1)&&(king1x-1<10)){
  1229. fullKingCheckWhite(king1x-1,king1y);
  1230. }
  1231. if ((checkWhite==1)&&(pieces[king1x][king1y-1]<'a')&&(king1y-1>1)&&(king1y-1<10)){
  1232. fullKingCheckWhite(king1x,king1y-1);
  1233. }
  1234. if ((checkWhite==1)&&(pieces[king1x-1][king1y-1]<'a')&&(king1y-1>1)&&(king1y-1<10)&&(king1x-1>1)&&(king1x-1<10)){
  1235. fullKingCheckWhite(king1x-1,king1y-1);
  1236. }
  1237. if ((checkWhite==1)&&(pieces[king1x+1][king1y-1]<'a')&&(king1y-1>1)&&(king1y-1<10)&&(king1x+1>1)&&(king1x+1<10)){
  1238. fullKingCheckWhite(king1x+1,king1y-1);
  1239. }
  1240. if ((checkWhite==1)&&(pieces[king1x-1][king1y+1]<'a')&&(king1y+1>1)&&(king1y+1<10)&&(king1x-1>1)&&(king1x-1<10)){
  1241. fullKingCheckWhite(king1x-1,king1y+1);
  1242. }
  1243. if (checkWhite==1){
  1244. checkMateBlack=0;
  1245. for (k=2;k<=9;k++){
  1246. for (l=2;l<=9;l++){
  1247. if (pieces[k][l]<'a'){
  1248. fullPieceCheckBlack(k,l);
  1249. if (checkMateBlack==1){
  1250. return;
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. }
  1257.  
  1258. void kingBlackStaleMate(){
  1259. checkBlack=1;
  1260. checkMateWhite=1;
  1261. if (((pieces[king2x+1][king2y]>='a')||(pieces[king2x+1][king2y]=='\0'))&&(king2x+1>1)&&(king2x+1<10)){
  1262. fullKingCheckBlack(king2x+1,king2y);
  1263. }
  1264. if ((checkBlack==1)&&((pieces[king2x][king2y+1]>='a')||(pieces[king2x][king2y+1]=='\0'))&&(king2y+1>1)&&(king2y+1<10)){
  1265. fullKingCheckBlack(king2x,king2y+1);
  1266. }
  1267. if ((checkBlack==1)&&((pieces[king2x+1][king2y+1]>='a')||(pieces[king2x+1][king2y+1]=='\0'))&&(king2y+1>1)&&(king2y+1<10)&&(king2x+1>1)&&(king2x+1<10)){
  1268. fullKingCheckBlack(king2x+1,king2y+1);
  1269. }
  1270. if ((checkBlack==1)&&((pieces[king2x-1][king2y]>='a')||(pieces[king2x-1][king2y]=='\0'))&&(king2x-1>1)&&(king2x-1<10)){
  1271. fullKingCheckBlack(king2x-1,king2y);
  1272. }
  1273. if ((checkBlack==1)&&((pieces[king2x][king2y-1]>='a')||(pieces[king2x][king2y-1]=='\0'))&&(king2y-1>1)&&(king2y-1<10)){
  1274. fullKingCheckBlack(king2x,king2y-1);
  1275. }
  1276. if ((checkBlack==1)&&((pieces[king2x-1][king2y-1]>='a')||(pieces[king2x-1][king2y-1]=='\0'))&&(king2y-1>1)&&(king2y-1<10)&&(king2x-1>1)&&(king2x-1<10)){
  1277. fullKingCheckBlack(king2x-1,king2y-1);
  1278. }
  1279. if ((checkBlack==1)&&((pieces[king2x+1][king2y-1]>='a')||(pieces[king2x+1][king2y-1]=='\0'))&&(king2y-1>1)&&(king2y-1<10)&&(king2x+1>1)&&(king2x+1<10)){
  1280. fullKingCheckBlack(king2x+1,king2y-1);
  1281. }
  1282. if ((checkBlack==1)&&((pieces[king2x-1][king2y+1]>='a')||(pieces[king2x-1][king2y+1]=='\0'))&&(king2y+1>1)&&(king2y+1<10)&&(king2x-1>1)&&(king2x-1<10)){
  1283. fullKingCheckBlack(king2x-1,king2y+1);
  1284. }
  1285. if (checkBlack==1){
  1286. checkMateWhite=0;
  1287. for (k=2;k<=9;k++){
  1288. for (l=2;l<=9;l++){
  1289. if ((pieces[k][l]=='\0')||(pieces[k][l]>='a')){
  1290. fullPieceCheckWhite(k,l);
  1291. if (checkMateWhite==1){
  1292. return;
  1293. }
  1294. }
  1295. }
  1296. }
  1297. }
  1298. }
  1299.  
  1300. void fullPieceCheckBlack(int x,int y){
  1301. if ((pieces[x-1][y+2]=='n')||(pieces[x+1][y+2]=='n')||(pieces[x-1][y-2]=='n')||(pieces[x+1][y-2]=='n')||(pieces[x+2][y-1]=='n')||(pieces[x+2][y+1]=='n')||(pieces[x-2][y-1]=='n')||(pieces[x-2][y+1]=='n')){
  1302. checkBlack=1;
  1303. checkMateBlack=1;
  1304. return;
  1305. }
  1306. else if (((pieces[x+1][y-1]=='p')||(pieces[x+1][y+1]=='p'))&&(pieces[x][y]>='A')&&(pieces[x][y]<='Z')){
  1307. checkBlack=1;
  1308. checkMateBlack=1;
  1309. return;
  1310. }
  1311. else if ((pieces[x+1][y]=='p')&&(pieces[x][y]=='\0')){
  1312. checkBlack=1;
  1313. checkMateBlack=1;
  1314. return;
  1315. }
  1316. else{
  1317. for(i=1; i<=7;i++){
  1318. if(x+i>9){
  1319. break;
  1320. }
  1321. else if(pieces[x+i][y]!='\0' && (pieces[x+i][y]!='r' && pieces[x+i][y]!='q')){
  1322. checkBlack=0;
  1323. checkMateBlack=0;
  1324. break;
  1325. }
  1326. else if(pieces[x+i][y]=='r'||pieces[x+i][y]=='q'){
  1327. checkBlack=1;
  1328. checkMateBlack=1;
  1329. return;
  1330. }
  1331. }
  1332. for(i=1; i<=7;i++){
  1333. if(x-i<2){
  1334. break;
  1335. }
  1336. else if(pieces[x-i][y]!='\0' && (pieces[x-i][y]!='r' && pieces[x-i][y]!='q')){
  1337. checkBlack=0;
  1338. checkMateBlack=0;
  1339. break;
  1340. }
  1341. else if(pieces[x-i][y]=='r'||pieces[x-i][y]=='q'){
  1342. checkBlack=1;
  1343. checkMateBlack=1;
  1344. return;
  1345. }
  1346. }
  1347. for(i=1; i<=7;i++){
  1348. if(y+i>9){
  1349. break;
  1350. }
  1351. else if(pieces[x][y+i]!='\0' && (pieces[x][y+i]!='r' && pieces[x][y+i]!='q')){
  1352. checkBlack=0;
  1353. checkMateBlack=0;
  1354. break;
  1355. }
  1356. else if(pieces[x][y+i]=='r'||pieces[x][y+i]=='q'){
  1357. checkBlack=1;
  1358. checkMateBlack=1;
  1359. return;
  1360. }
  1361. }
  1362. for(i=1; i<=7;i++){
  1363. if(y-i<2){
  1364. break;
  1365. }
  1366. else if(pieces[x][y-i]!='\0' && (pieces[x][y-i]!='r' && pieces[x][y-i]!='q')){
  1367. checkBlack=0;
  1368. checkMateBlack=0;
  1369. break;
  1370. }
  1371. else if(pieces[x][y-i]=='r'||pieces[x][y-i]=='q'){
  1372. checkBlack=1;
  1373. checkMateBlack=1;
  1374. return;
  1375. }
  1376. }
  1377. for(i=1; i<=7;i++){
  1378. if(x+i>9 && y+i>9){
  1379. break;
  1380. }else if(pieces[x+i][y+i]!='\0' && (pieces[x+i][y+i]!='b' && pieces[x+i][y+i]!='q')){
  1381. checkBlack=0;
  1382. checkMateBlack=0;
  1383. break;
  1384. }
  1385. else if(pieces[x+i][y+i]=='b'||pieces[x+i][y+i]=='q'){
  1386. checkBlack=1;
  1387. checkMateBlack=1;
  1388. return;
  1389. }
  1390. }
  1391. for(i=1; i<=7;i++){
  1392. if(x-i<2 && y+i>9){
  1393. break;
  1394. }else if(pieces[x-i][y+i]!='\0' && (pieces[x-i][y+i]!='b' && pieces[x-i][y+i]!='q')){
  1395. checkBlack=0;
  1396. checkMateBlack=0;
  1397. break;
  1398. }
  1399. else if(pieces[x-i][y+i]=='b'||pieces[x-i][y+i]=='q'){
  1400. checkBlack=1;
  1401. checkMateBlack=1;
  1402. return;
  1403. }
  1404. }
  1405. for(i=1; i<=7;i++){
  1406. if(x-i<2 && y-i<2){
  1407. break;
  1408. }else if(pieces[x-i][y-i]!='\0' && (pieces[x-i][y-i]!='b' && pieces[x-i][y-i]!='q')){
  1409. checkBlack=0;
  1410. checkMateBlack=0;
  1411. break;
  1412. }
  1413. else if(pieces[x-i][y-i]=='b'||pieces[x-i][y-i]=='q'){
  1414. checkBlack=1;
  1415. checkMateBlack=1;
  1416. return;
  1417. }
  1418. }
  1419. for(i=1; i<=7;i++){
  1420. if(x+i>9 && y-i<2){
  1421. break;
  1422. }else if(pieces[x+i][y-i]!='\0' && (pieces[x+i][y-i]!='b' && pieces[x+i][y-i]!='q')){
  1423. checkBlack=0;
  1424. checkMateBlack=0;
  1425. break;
  1426. }
  1427. else if(pieces[x+i][y-i]=='b'||pieces[x+i][y-i]=='q'){
  1428. checkBlack=1;
  1429. checkMateBlack=1;
  1430. return;
  1431. }
  1432. }
  1433. }
  1434. }
  1435. void fullPieceCheckWhite(int x,int y){
  1436. if ((pieces[x-1][y+2]=='N')||(pieces[x+1][y+2]=='N')||(pieces[x-1][y-2]=='N')||(pieces[x+1][y-2]=='N')||(pieces[x+2][y-1]=='N')||(pieces[x+2][y+1]=='N')||(pieces[x-2][y-1]=='N')||(pieces[x-2][y+1]=='N')){
  1437. checkWhite=1;
  1438. checkMateWhite=1;
  1439. return;
  1440. }
  1441. else if (((pieces[x-1][y-1]=='P')||(pieces[x-1][y+1]=='p'))&&(pieces[x][y]>='a')&&(pieces[x][y]<='z')){
  1442. checkBlack=1;
  1443. checkMateBlack=1;
  1444. return;
  1445. }
  1446. else if ((pieces[x-1][y]=='P')&&(pieces[x][y]=='\0')){
  1447. checkBlack=1;
  1448. checkMateBlack=1;
  1449. return;
  1450. }
  1451. else{
  1452. for(i=1; i<=7;i++){
  1453. if(x+i>9){
  1454. break;
  1455. }
  1456. else if(pieces[x+i][y]!='\0' && (pieces[x+i][y]!='R' && pieces[x+i][y]!='Q')){
  1457. checkWhite=0;
  1458. checkMateWhite=0;
  1459. break;
  1460. }
  1461. else if(pieces[x+i][y]=='R'||pieces[x+i][y]=='Q'){
  1462. checkWhite=1;
  1463. checkMateWhite=1;
  1464. return;
  1465. }
  1466. }
  1467. for(i=1; i<=7;i++){
  1468. if(x-i<2){
  1469. break;
  1470. }
  1471. else if(pieces[x-i][y]!='\0' && (pieces[x-i][y]!='R' && pieces[x-i][y]!='Q')){
  1472. checkWhite=0;
  1473. checkMateWhite=0;
  1474. break;
  1475. }
  1476. else if(pieces[x-i][y]=='R'||pieces[x-i][y]=='Q'){
  1477. checkWhite=1;
  1478. checkMateWhite=1;
  1479. return;
  1480. }
  1481. }
  1482. for(i=1; i<=7;i++){
  1483. if(y+i>9){
  1484. break;
  1485. }
  1486. else if(pieces[x][y+i]!='\0' && (pieces[x][y+i]!='R' && pieces[x][y+i]!='Q')){
  1487. checkWhite=0;
  1488. checkMateWhite=0;
  1489. break;
  1490. }
  1491. else if(pieces[x][y+i]=='R'||pieces[x][y+i]=='Q'){
  1492. checkWhite=1;
  1493. checkMateWhite=1;
  1494. return;
  1495. }
  1496. }
  1497. for(i=1; i<=7;i++){
  1498. if(y-i<2){
  1499. break;
  1500. }
  1501. else if(pieces[x][y-i]!='\0' && (pieces[x][y-i]!='R' && pieces[x][y-i]!='Q')){
  1502. checkWhite=0;
  1503. checkMateWhite=0;
  1504. break;
  1505. }
  1506. else if(pieces[x][y-i]=='R'||pieces[x][y-i]=='Q'){
  1507. checkWhite=1;
  1508. checkMateWhite=1;
  1509. return;
  1510. }
  1511. }
  1512. for(i=1; i<=7;i++){
  1513. if(x+i>9 && y+i>9){
  1514. break;
  1515. }else if(pieces[x+i][y+i]!='\0' && (pieces[x+i][y+i]!='B' && pieces[x+i][y+i]!='Q')){
  1516. checkWhite=0;
  1517. checkMateWhite=0;
  1518. break;
  1519. }
  1520. else if(pieces[x+i][y+i]=='B'||pieces[x+i][y+i]=='Q'){
  1521. checkWhite=1;
  1522. checkMateWhite=1;
  1523. return;
  1524. }
  1525. }
  1526. for(i=1; i<=7;i++){
  1527. if(x-i<2 && y+i>9){
  1528. break;
  1529. }else if(pieces[x-i][y+i]!='\0' && (pieces[x-i][y+i]!='B' && pieces[x-i][y+i]!='Q')){
  1530. checkWhite=0;
  1531. checkMateWhite=0;
  1532. break;
  1533. }
  1534. else if(pieces[x-i][y+i]=='B'||pieces[x-i][y+i]=='Q'){
  1535. checkWhite=1;
  1536. checkMateWhite=1;
  1537. return;
  1538. }
  1539. }
  1540. for(i=1; i<=7;i++){
  1541. if(x-i<2 && y-i<2){
  1542. break;
  1543. }else if(pieces[x-i][y-i]!='\0' && (pieces[x-i][y-i]!='B' && pieces[x-i][y-i]!='Q')){
  1544. checkWhite=0;
  1545. checkMateWhite=0;
  1546. break;
  1547. }
  1548. else if(pieces[x-i][y-i]=='B'||pieces[x-i][y-i]=='Q'){
  1549. checkWhite=1;
  1550. checkMateWhite=1;
  1551. return;
  1552. }
  1553. }
  1554. for(i=1; i<=7;i++){
  1555. if(x+i>9 && y-i<2){
  1556. break;
  1557. }else if(pieces[x+i][y-i]!='\0' && (pieces[x+i][y-i]!='B' && pieces[x+i][y-i]!='Q')){
  1558. checkWhite=0;
  1559. checkMateWhite=0;
  1560. break;
  1561. }
  1562. else if(pieces[x+i][y-i]=='B'||pieces[x+i][y-i]=='Q'){
  1563. checkWhite=1;
  1564. checkMateWhite=1;
  1565. return;
  1566. }
  1567. }
  1568. }
  1569. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement