Advertisement
anas_harby

Untitled

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