Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<stdbool.h>
  4. #include<ctype.h>
  5. int flag =1 ;
  6. int lostb =0;
  7. int lostw =0 ;
  8. char lost_white[16];
  9. char lost_black[16];
  10. char list[8][8][100000];
  11. int in=-1;
  12. int redo=-1;
  13. int d=2;
  14. int kingswhiterow=0;
  15. int kingswhitecoloumn=4;
  16. int kingsblackrow=7;
  17. int kingsblackcoloumn=4;
  18. char white_black(int fromr,int fromc){
  19. if(fromr%2==0&&fromc%2==0){
  20. return '.';
  21. }
  22. else if (fromr%2!=0&&fromc%2!=0){
  23. return '.';
  24. }
  25. else if (fromc%2==0&&fromr%2!=0){
  26. return '-';
  27. }
  28. else {return '-';}
  29. }
  30. int max(int a,int b)
  31. {
  32. if(a>b)
  33. {
  34. return a;
  35. }
  36. else
  37. {
  38. return b;
  39. }
  40. }
  41. int min (int a,int b)
  42. {
  43. if(a<b)
  44. {
  45. return a;
  46. }
  47. else
  48. {
  49. return b;
  50. }
  51. }
  52. char board[8][8];
  53. char c[3];
  54. int player=0;
  55. char c2[2];
  56. char white ='-';
  57. char black ='.';
  58. char pawnw='p',pawnb='P',rookw='r',knightw='n',bishopw='b',queenw='q',kingw='k',rookb='R',knightb='N',bishopb='B',queenb='Q',kingb='K';
  59. void firstDisplay(){
  60. for(int i=0;i<8;i++){
  61. for(int j=0;j<8;j++){
  62. if(i==1){
  63. board[i][j]=pawnw;
  64. }
  65. else if (i==6){
  66. board[i][j]=pawnb;
  67. }
  68. else if (i!=7||i!=0||i!=1||i!=6){
  69. if((i==2||i==4)&&(j==0||j==2||j==4||j==6)){
  70. board[i][j]=black;
  71.  
  72. }
  73. else if ((i==3||i==5)&&(j==1||j==3||j==5||j==7)){
  74. board[i][j]=black;
  75. }
  76. else {
  77. board[i][j]=white;
  78. }
  79.  
  80. }
  81.  
  82. }
  83. }
  84.  
  85. board[0][0]=rookw;
  86. board[7][0]=rookb;
  87. board[0][1]=knightw;
  88. board[7][1]=knightb;
  89. board[0][2]=bishopw;
  90. board[7][2]=bishopb;
  91. board[0][3]=queenw;
  92. board[7][3]=queenb;
  93. board[0][4]=kingw;
  94. board[7][4]=kingb;
  95. board[0][5]=bishopw;
  96. board[3][3]=bishopb;
  97. board[0][6]=knightw;
  98. board[7][6]=knightb;
  99. board[0][7]=rookw;
  100. board[7][7]=rookb;
  101. board[6][0]=pawnb;
  102. board[1][0]=pawnw;
  103. //board[3][4]='k';
  104. //board[2][2]='A';
  105. //board[5][0]='a';
  106. //board[6][3]='-';
  107. //board[7][5]='k';
  108. //board[0][4]='-';
  109. board[6][0]='p';
  110. board[7][0]='-';
  111. board[7][1]='R';
  112. board[6][1]='-';
  113. board[5][1]='R';
  114. }
  115. void printDisplay(){
  116.  
  117. system("cls");
  118. int v=1;
  119. in++;
  120. printf("\n");
  121. printf("\t\t ");
  122. for(int i=0;i<8;i++)
  123. {
  124. printf(" %c",'A'+i);
  125. }
  126. printf("\n\n");
  127. for(int i=7;i>=0;i--){
  128. if(v!=9)
  129. {
  130. printf("\t\t %d ",v);
  131. v++;
  132. }
  133. else
  134. {
  135. printf(" ");
  136. }
  137. for (int j =0;j<8;j++){
  138. list[i][j][in]=board[i][j];
  139. printf(" %c",board[i][j]);
  140. }
  141. if(i!=-1)
  142. {
  143. printf(" %d",i+1);
  144. }
  145. printf("\n\n");
  146. }
  147. printf("\t\t ");
  148. for(int i=0;i<8;i++)
  149. {
  150. printf(" %c",'A'+i);
  151. }
  152. printf("\n");
  153. printf("lost in white");
  154. for(int i =0;i<lostw;i++){printf(" %c ",lost_white[i]);}
  155. printf("\n");
  156. printf("lost in black");
  157. for(int i =0;i<lostb;i++){printf(" %c ",lost_black[i]);}
  158. printf("\n");
  159. printf("For Undo press U and for Redo press R");
  160. printf("\n");
  161.  
  162. }
  163. int fromc,fromr,tor,toc;
  164. void read_move(char c[],char c2[])
  165. {
  166. scanf("%d",&c[2]);
  167. gets(c);
  168. if(c[0]=='U'){fromr=0;fromc=0;tor=0;toc=0;}
  169. else if(c[0]=='R'){fromr=0;fromc=0;tor=0;toc=0;}
  170. else{
  171. fromc=c[0]-97;
  172. fromr=c[1]-'0'-1;
  173. //printf("%c",board[fromr][fromc]);
  174. printf("To ");
  175. gets(c2);
  176. toc=c2[0]-97;
  177. tor=c2[1]-'0'-1;
  178. }}
  179. int validinput(int fromr,int fromc,int tor,int toc)
  180. {if(c[0]=='U'){
  181. return 1;}
  182. else if(c[0]=='R'){return 1 ;}
  183. if(fromr>7||fromc>7||fromr<0||fromc<0)
  184. {
  185. return 0;
  186. }
  187. else if(tor>7||toc>7||tor<0||toc<0)
  188. {
  189. return 0;
  190. }
  191. else if(c=='\n'||c2=='\n')
  192. {
  193. return 0;
  194. }
  195. else
  196. {
  197. return 1;
  198. }
  199. }
  200. int validpawn(int fromr,int fromc,int tor,int toc)
  201. {
  202.  
  203. if(board[fromr][fromc]=='p')
  204. {
  205. if((fromr==1)&&(fromc==0||fromc==1||fromc==2||fromc==3||fromc==4||fromc==5||fromc==6||fromc==7))
  206. {
  207. if(tor-fromr!=1&&tor-fromr!=2)
  208. {
  209. //printf("df");
  210. return 0;
  211. }
  212. else if(tor-fromr==2)
  213. {
  214. if(board[tor-1][fromc]!='-'&&board[tor-1][fromc]!='.')
  215. {
  216. return 0;
  217. }
  218. }
  219. }
  220. else if(tor-fromr!=1)
  221. {
  222. //printf("df");
  223. return 0;
  224. }
  225. if(toc-fromc!=0&&tor-fromr==1)//coloumns
  226. {
  227. if(toc-fromc==1||toc-fromc==-1)
  228. {
  229. //printf("d");
  230. if(board[tor][toc]!='.'&&board[tor][toc]!='-')
  231. {
  232. if(isupper(board[tor][toc]))
  233. {
  234. // printf("ad");
  235. return 1;
  236. }
  237. }
  238. else
  239. {
  240. //printf("sdff");
  241. return 0;
  242. }
  243. }
  244. else
  245. {
  246. return 0;
  247.  
  248. }
  249. }
  250. if(board[tor][toc]!='-'&&board[tor][toc]!='.')
  251. {
  252. return 0;
  253. }
  254.  
  255. else
  256. {
  257. return 1;
  258. }
  259. }
  260. else if(board[fromr][fromc]=='P')
  261. {
  262. if((fromr==6)&&(fromc==0||fromc==1||fromc==2||fromc==3||fromc==4||fromc==5||fromc==6||fromc==7))
  263. {
  264. if(tor-fromr!=-1&&tor-fromr!=-2)
  265. {
  266. return 0;
  267. }
  268. else if(tor-fromr==-2)
  269. {
  270. if(board[tor+1][fromc]!='-'&&board[tor+1][fromc]!='.')
  271. {
  272. return 0;
  273. }
  274. }
  275. }
  276. else if(tor-fromr!=-1)
  277. {
  278. return 0;
  279. }
  280. if(toc-fromc!=0&&tor-fromr==-1)
  281. {
  282. if(toc-fromc==1||toc-fromc==-1)
  283. {
  284. if(board[tor][toc]!='.'&&board[tor][toc]!='-')//it just need to add all of the same chess colours as it can't move if one of them is there
  285. {
  286. if(islower(board[tor][toc]))
  287. return 1;
  288. }
  289. else
  290. {
  291. return 0;
  292. }
  293. }
  294. else
  295. {
  296. return 0;
  297.  
  298. }
  299. }
  300. if(board[tor][toc]!='-'&&board[tor][toc]!='.')
  301. {
  302. return 0;
  303. }
  304.  
  305. else
  306. {
  307. return 1;
  308. }
  309. }
  310. }
  311. int validrook(int fromr,int fromc,int tor,int toc){
  312. if(board[fromr][fromc]=='r'||board[fromr][fromc]=='R')
  313. {
  314. if(board[fromr][fromc]=='r'&&islower(board[tor][toc]))
  315. {
  316. return 0;
  317. }
  318. else if(board[fromr][fromc]=='R'&&isupper(board[tor][toc]))
  319. {
  320. return 0;
  321. }
  322. if(tor-fromr==0&&toc-fromc!=0)
  323. {
  324. for(int i=min(toc,fromc)+1;i<max(toc,fromc);i++)
  325. {
  326. if(board[fromr][i]!='-'&&board[fromr][i]!='.')
  327. {
  328. // printf("empty");
  329. return 0;
  330. }
  331. }
  332. return 1;
  333. }
  334. else if(tor-fromr!=0&&toc-fromc==0)
  335. {
  336. //printf("a7a");
  337. for(int i=min(tor,fromr)+1;i<max(tor,fromr);i++)
  338. {
  339. if(board[i][fromc]!='-'&&board[i][fromc]!='.')
  340. {
  341. // printf("empty");
  342. return 0;
  343. }
  344. }
  345. return 1;
  346. }
  347. else
  348. {
  349. return 0;
  350. }
  351. }
  352. }
  353. int validknight(int fromr,int fromc,int tor,int toc){
  354. if(board[fromr][fromc]=='n'||board[fromr][fromc]=='N'){
  355. if(abs(toc-fromc)==2&&abs(tor-fromr)==1||abs(toc-fromc)==1&&abs(tor-fromr)==2){
  356. if (board[tor][toc]=='-'||board[tor][toc]=='.'){
  357. return 1 ;
  358. }
  359. else if (((board[fromr][fromc]=='n')&&isupper((int)board[tor][toc]))==1||((board[fromr][fromc]=='N')&&islower(board[tor][toc]))){
  360. return 1;
  361. }
  362. }
  363. }
  364. return 0 ;
  365. }
  366. int validking(int fromr,int fromc,int tor,int toc){
  367. if(board[fromr][fromc]=='k'||board[fromr][fromc]=='K'){
  368. if(abs(toc-fromc)==1&&tor-fromr==0||abs(tor-fromr)==1&&toc-fromc==0||abs(tor-fromr)==1&&abs(toc-fromc)==1){
  369. if (board[tor][toc]=='-'||board[tor][toc]=='.'){
  370. return 1 ;
  371. }
  372. else if (((board[fromr][fromc]=='k')&&isupper((int)board[tor][toc]))==1||((board[fromr][fromc]=='K')&&islower(board[tor][toc]))){
  373. return 1;
  374. }
  375.  
  376. }
  377.  
  378. }
  379. return 0 ;
  380. }
  381. int validbishop(int fromr,int fromc,int tor,int toc)
  382. {
  383. if(board[fromr][fromc]=='b'||board[fromr][fromc]=='B')
  384. {
  385. if(abs(tor-fromr)==abs(toc-fromc))
  386. {
  387. if(board[fromr][fromc]=='b'&&islower(board[tor][toc]))
  388. {
  389. // printf("a");
  390. return 0;
  391. }
  392. else if(board[fromr][fromc]=='B'&&isupper(board[tor][toc]))
  393. {
  394. // printf("a7a");
  395. return 0;
  396. }
  397. int j=min(fromc,toc)+1;
  398. int detect;
  399. if((fromr==min(fromr,tor)&&fromc==min(fromc,toc))||(tor==min(fromr,tor)&&toc==min(fromc,toc)))
  400. {
  401. detect=1;
  402. }
  403. else
  404. {
  405. j=max(toc,fromc)-1;
  406. detect=-1;
  407. }
  408. for(int i=min(fromr,tor)+1;i<max(fromr,tor);i++)
  409. {
  410. if(board[i][j]!='-'&&board[i][j]!='.')
  411. {
  412. return 0;
  413. }
  414. j+=detect;
  415. }
  416. return 1;
  417. }
  418. else
  419. {
  420. return 0;
  421. }
  422. }
  423. }
  424. int validqueen (int fromr,int fromc,int tor,int toc){
  425. if(board[fromr][fromc]=='q'||board[fromr][fromc]=='Q'){
  426. if(abs(tor-fromr)==abs(toc-fromc))
  427. {
  428. if(board[fromr][fromc]=='q'&&islower(board[tor][toc]))
  429. {
  430. //printf("a");
  431. return 0;
  432. }
  433. else if(board[fromr][fromc]=='Q'&&isupper(board[tor][toc]))
  434. {
  435. return 0;
  436. }
  437. int j=min(fromc,toc)+1;
  438. int detect;
  439. if((fromr==min(fromr,tor)&&fromc==min(fromc,toc))||(tor==min(fromr,tor)&&toc==min(fromc,toc)))
  440. {
  441. detect=1;
  442. }
  443. else
  444. {
  445. j=max(toc,fromc)-1;
  446. detect=-1;
  447. }
  448. for(int i=min(fromr,tor)+1;i<max(fromr,tor);i++)
  449. {
  450. if(board[i][j]!='-'&&board[i][j]!='.')
  451. {
  452. return 0;
  453. }
  454. j+=detect;
  455. }
  456. return 1;
  457. }
  458. else if(board[fromr][fromc]=='q'&&islower(board[tor][toc]))
  459. {
  460. return 0;
  461. }
  462. else if(board[fromr][fromc]=='Q'&&isupper(board[tor][toc]))
  463. {
  464. return 0;
  465. }
  466. if(tor-fromr==0&&toc-fromc!=0)
  467. {
  468. for(int i=min(toc,fromc)+1;i<max(toc,fromc);i++)
  469. {
  470. if(board[fromr][i]!='-'&&board[fromr][i]!='.')
  471. {
  472. // printf("empty");
  473. return 0;
  474. }
  475. }
  476. return 1;
  477. }
  478. else if(tor-fromr!=0&&toc-fromc==0)
  479. {
  480. // printf("a7a");
  481. for(int i=min(tor,fromr)+1;i<max(tor,fromr);i++)
  482. {
  483. if(board[i][fromc]!='-'&&board[i][fromc]!='.')
  484. {
  485. // printf("empty");
  486. return 0;
  487. }
  488. }
  489. return 1;
  490. }
  491. else
  492. {
  493. return 0;
  494. }
  495.  
  496. }
  497. }
  498. void make_move (int fromr,int fromc,int tor,int toc){
  499. if(c[0]=='U'){if(player==1){player=2;}
  500. else {player=1;}
  501. undo();}
  502. else if(c[0]=='R'){if(player==1){player=2;}
  503. else {player=1;}redomove();}
  504. else{
  505. if(board[tor][toc]!='-'&&board[tor][toc]!='.'){
  506. if(isupper((int)board[tor][toc])==1){
  507. lost_black[lostb]=board[tor][toc];
  508. lostb++;
  509. }
  510. else{
  511. lost_white[lostw]=board[tor][toc];
  512. lostw++;
  513. }
  514. board[tor][toc]=board[fromr][fromc];
  515. board[fromr][fromc]=white_black(fromr,fromc);
  516. permotion();
  517. printDisplay() ;
  518. }
  519. else {
  520. board[tor][toc]=board[fromr][fromc];
  521. board[fromr][fromc]=white_black(fromr,fromc);
  522. permotion();
  523. printDisplay();
  524. }}}
  525. int validmove(int fromr,int fromc,int tor,int toc)
  526. {
  527. if(islower(board[fromr][fromc])&&player!=1)
  528. {
  529. return 0;
  530. }
  531. else if(isupper(board[fromr][fromc])&&player!=2)
  532. {
  533. return 0;
  534. }
  535. if(validinput(fromr,fromc,tor,toc)==1&&validpawn(fromr,fromc,tor,toc)==1)
  536. {
  537. return checknow(fromr,fromc,tor,toc);
  538. }
  539. else if(validinput(fromr,fromc,tor,toc)==1&&validrook(fromr,fromc,tor,toc)==1)
  540. {
  541. return checknow(fromr,fromc,tor,toc);
  542. }
  543. else if(validinput(fromr,fromc,tor,toc)==1&&validknight(fromr,fromc,tor,toc)==1)
  544. {
  545. return checknow(fromr,fromc,tor,toc);
  546. }
  547. else if(validinput(fromr,fromc,tor,toc)==1&&validking(fromr,fromc,tor,toc)==1)
  548. {
  549. return checknow(fromr,fromc,tor,toc);
  550. }
  551. else if(validinput(fromr,fromc,tor,toc)==1&&validbishop(fromr,fromc,tor,toc)==1)
  552. {
  553. return checknow(fromr,fromc,tor,toc);
  554. }
  555. else if(validinput(fromr,fromc,tor,toc)==1&&validqueen(fromr,fromc,tor,toc)==1)
  556. {
  557. return checknow(fromr,fromc,tor,toc);
  558. }
  559.  
  560. else
  561. {
  562. return 0;
  563. }
  564. }
  565. int checknow(fromr,fromc,tor,toc)
  566. {
  567. char temp=board[fromr][fromc];
  568. char temp2=board[tor][toc];
  569. board[tor][toc]=board[fromr][fromc];
  570. board[fromr][fromc]='-';
  571. if(!check())
  572. {
  573. board[fromr][fromc]=temp;
  574. board[tor][toc]=temp2;
  575. return 1;
  576. }
  577. board[fromr][fromc]=temp;
  578. board[tor][toc]=temp2;
  579. return 0;
  580. }
  581. int check()
  582. {
  583. int x,y;
  584. if(player==1)
  585. {
  586. for(int i=0;i<8;i++)
  587. {
  588. for(int j=0;j<8;j++)
  589. {
  590. if(board[i][j]=='k')
  591. {
  592. x=i;
  593. y=j;
  594. break;
  595. }
  596. }
  597. }
  598. }
  599. else if(player==2)
  600. {
  601. for(int i=0;i<8;i++)
  602. {
  603. for(int j=0;j<8;j++)
  604. {
  605. if(board[i][j]=='K')
  606. {
  607. x=i;
  608. y=j;
  609. break;
  610. }
  611. }
  612. }
  613. }
  614. int temp=player;
  615. player=(player%2)+1;
  616. for(int i=0;i<8;i++)
  617. {
  618. for(int j=0;j<8;j++)
  619. {
  620. if(validmove(i,j,x,y))
  621. {
  622. //printf("%d %d %d %d\n",i+1,j+1,x+1,y+1);
  623. player=temp;
  624. return 1;
  625. }
  626. }
  627. }
  628. player=temp;
  629. return 0;
  630. }
  631. int checkmat()
  632. {
  633. if(check())
  634. {
  635. // printf("asd");
  636. for(int i=0;i<8;i++)
  637. {
  638. for(int j=0;j<8;j++)
  639. {
  640. for(int k=0;k<8;k++)
  641. {
  642. for(int l=0;l<8;l++)
  643. {
  644. if(validmove(i,j,k,l))
  645. {
  646. // printf(" fff%d %d %d %d\n",i+1,j+1,k+1,l+1);
  647. return 0;
  648. }
  649. }
  650. }
  651. }
  652. }
  653. return 1;
  654. }
  655. else
  656. {
  657. return 0;
  658. }
  659. }
  660. int stalemat()
  661. {
  662. if(!check())
  663. {
  664. for(int i=0;i<8;i++)
  665. {
  666. for(int j=0;j<8;j++)
  667. {
  668. if(board[i][j]!='-'&&board[i][j]!='.')
  669. {
  670. for(int x=0;x<8;x++)
  671. {
  672. for(int y=0;y<8;y++)
  673. {
  674. if(validmove(i,j,x,y))
  675. {
  676. return 0;
  677. }
  678. }
  679. }
  680. }
  681. }
  682. }
  683. return 1;
  684. }
  685. else
  686. {
  687. return 0;
  688. }
  689. }
  690. int k=0;
  691. void playgame()
  692. {
  693. printf("CHOOSE 1 FOR SAVED GAME\nCHOOSE 2 FOR NEW GAME\n");
  694. scanf("%d",&d);
  695. firstDisplay();
  696. if(d!=1)
  697. {
  698. printDisplay();
  699. }
  700. else
  701. {
  702. load();
  703. }
  704. while(true)
  705. {
  706. if(player==1)
  707. {
  708. player=2;
  709. }
  710. else
  711. {
  712. player=1;
  713. }
  714. //player=2;
  715. if(checkmat())
  716. {
  717. system("cls");
  718. printf("\n");
  719. printf("%d",(player%2)+1);
  720. printf("WINS!!");
  721. break;
  722. }
  723. else if(check())
  724. {
  725. printf("Player %d checks Player %d\n",(player%2)+1,player);
  726. }
  727. else if(stalemat())
  728. {
  729. system("cls");
  730. printf("\n");
  731. printf("DRAW");
  732. break;
  733. }
  734. //player;
  735. printf("Player %d's turn: ",player);
  736. read_move(c,c2);
  737. if(c[0]!='U'&&c[0]!='R')
  738. {
  739. while(validmove(fromr,fromc,tor,toc)!=1)
  740. {
  741. printf("invalid");
  742. read_move(c,c2);
  743. }
  744. }
  745. make_move(fromr,fromc,tor,toc);
  746. save();
  747. }
  748. }
  749.  
  750. void save()
  751. {
  752. FILE * fpointer;
  753. fpointer=fopen("save.text","w");
  754. for(int i=7;i>=0;i--)
  755. {
  756. for(int j=0;j<8;j++)
  757. {
  758. fprintf(fpointer,"%c",board[i][j]);
  759. }
  760. }
  761. fprintf(fpointer,"%d",player);
  762. if(lostw!=0)
  763. {
  764. for(int i=0;i<=lostw;i++)
  765. {
  766. fprintf(fpointer,"%c",lost_white[i]);
  767. }
  768. }
  769. if(lostb!=0)
  770. {
  771. for(int i=0;i<=lostb;i++)
  772. {
  773. fprintf(fpointer,"%c",lost_black[i]);
  774. }
  775. }
  776. fclose(fpointer);
  777. }
  778. char s[150];
  779. void load()
  780. {
  781. FILE * fpointer;
  782. fpointer=fopen("save.text","r");
  783. if(fpointer=fopen("save.text","r")){
  784. int counter=0;
  785. while(!feof(fpointer))
  786. {
  787. fgets(s,200,fpointer);
  788. for(int i=7;i>=0;i--)
  789. {
  790. for(int j=0;j<8;j++)
  791. {
  792. board[i][j]=s[counter];
  793. counter++;
  794. }
  795. }
  796. player=s[counter]-'0';
  797. counter++;
  798. int i=0;
  799. while(islower(s[counter]))
  800. {
  801. lost_white[i]=s[counter];
  802. lostw++;
  803. i++;
  804. counter++;
  805. }
  806. i=0;
  807. if(s[counter]=' ')
  808. {
  809. counter++;
  810. }
  811. while(isupper(s[counter]))
  812. {
  813. lost_black[i]=s[counter];
  814. i++;
  815. lostb++;
  816. counter++;
  817. }
  818. break;
  819. }
  820. printDisplay();
  821. }
  822. else{printDisplay();}}
  823. int cunt=0;
  824. int cunt2=0;
  825. int cunt3=0;
  826. int undo()
  827. {
  828. //player=(player%2)+1;
  829. if(in<=0)
  830. {
  831. return 0;
  832. }
  833. cunt++;
  834. player=(player%2)+1;
  835. int countblack_after=0;
  836. int countwhite_after=0;
  837. int countblack_before=0;
  838. int countwhite_before=0;
  839. for(int i=7;i>=0;i--)
  840. {
  841. for(int j=0;j<8;j++)
  842. {
  843. if(board[i][j]!='-'&&board[i][j]!='.')
  844. {
  845. if(islower(board[i][j]))
  846. {
  847. countwhite_before++;
  848. }
  849. else if(isupper(board[i][j]))
  850. {
  851. countblack_before++;
  852. }
  853. }
  854. board[i][j]=list[i][j][in-1];
  855. if(board[i][j]!='-'&&board[i][j]!='.')
  856. {
  857. if(islower(board[i][j]))
  858. {
  859. countwhite_after++;
  860. }
  861. else if(isupper(board[i][j]))
  862. {
  863. countblack_after++;
  864. }
  865. }
  866. }
  867. }
  868. if(countwhite_after>countwhite_before)
  869. {
  870. lostw--;
  871. }
  872. if(countblack_after>countblack_before)
  873. {
  874. // printf("%d %d\n",countblack_before,countblack_after);
  875. lostb--;
  876. }
  877. in=in-2;
  878. printDisplay();
  879. cunt3=in;
  880. return 1;
  881. }
  882. void redomove()
  883. {
  884. cunt2++;
  885. if(cunt==0||cunt2>cunt||cunt3!=in)
  886. {
  887. cunt2--;
  888. return;
  889. }
  890. player=(player%2)+1;
  891. int countblack_after=0;
  892. int countwhite_after=0;
  893. int countblack_before=0;
  894. int countwhite_before=0;
  895. for(int i=7;i>=0;i--)
  896. {
  897. for(int j=0;j<8;j++)
  898. {
  899. if(board[i][j]!='-'&&board[i][j]!='.')
  900. {
  901. if(islower(board[i][j]))
  902. {
  903. countwhite_before++;
  904. }
  905. else if(isupper(board[i][j]))
  906. {
  907. countblack_before++;
  908. }
  909. }
  910. board[i][j]=list[i][j][in+1];
  911. if(board[i][j]!='-'&&board[i][j]!='.')
  912. {
  913. if(islower(board[i][j]))
  914. {
  915. countwhite_after++;
  916. }
  917. else if(isupper(board[i][j]))
  918. {
  919. countblack_after++;
  920. }
  921. }
  922. }
  923. }
  924. if(countwhite_after<countwhite_before)
  925. {
  926. lostw++;
  927. }
  928. else if(countblack_after<countblack_before)
  929. {
  930. lostb++;
  931. }
  932. in-1;
  933. printDisplay();
  934. }
  935. char permote='p';
  936. int permotion()
  937. {
  938. if(board[tor][toc]=='p'&&tor==7)
  939. {
  940. printf("WHAT DO YOU WANT TO PERMOTE THE PAWN TO?");
  941. scanf("%c",&permote);
  942. while(!islower(permote)||permote=='k')
  943. {
  944. printf("INVALID PERMOTION\N");
  945. scanf("%c",&permote);
  946. }
  947. board[tor][toc]=permote;
  948. //p=1;
  949. return 1;
  950. }
  951. else if(board[tor][toc]=='P'&&tor==0)
  952. {
  953. printf("WHAT DO YOU WANT TO PERMOTE THE PAWN TO?");
  954. scanf("%c",&permote);
  955. while(!isupper(permote)||permote=='K')
  956. {
  957. printf("INVALID PERMOTION\N");
  958. scanf("%c",&permote);
  959. }
  960. board[tor][toc]=permote;
  961. // p=1;
  962. return 1;
  963. }
  964. return 0;
  965. }
  966. int main()
  967. {
  968. playgame();
  969. // read_move(c,c2);
  970. return 0;
  971. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement