Advertisement
anas_harby

Untitled

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