Advertisement
Seif45

Untitled

Dec 7th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. char pieces[12][12];
  5. char gameBoard [12][12];
  6. int i,j;
  7.  
  8. void gameBoardBorders(){
  9. for (i=0;i<12;i++){
  10. for (j=0;j<12;j++){
  11. gameBoard[i][j]='\0';
  12. }
  13. }
  14. for (i=0;i<12;i+=11){
  15. for (j=2;j<10;j++){
  16. gameBoard[i][j]='A'+(j-2);
  17. }
  18. }
  19. for (j=2;j<10;j++){
  20. gameBoard[1][j]='-';
  21. gameBoard[10][j]='-';
  22. }
  23. for (i=2;i<10;i++){
  24. for (j=0;j<12;j+=11){
  25. gameBoard[i][j]='8'-(i-2);
  26. }
  27. }
  28. for (i=2;i<10;i++){
  29. gameBoard[i][1]='|';
  30. gameBoard[i][10]='|';
  31. }
  32.  
  33. }
  34.  
  35. void checkerBoard(){
  36. for (i=2;i<10;i++){
  37. for (j=2;j<10;j+=2){
  38. if (i%2==0){
  39. gameBoard[i][j]='.';
  40. }
  41. else {
  42. gameBoard[i][j]='+';
  43. }
  44. }
  45. }
  46. for (i=2;i<10;i++){
  47. for (j=3;j<10;j+=2){
  48. if (i%2==0){
  49. gameBoard[i][j]='+';
  50. }
  51. else {
  52. gameBoard[i][j]='.';
  53. }
  54. }
  55. }
  56. }
  57.  
  58. void startingChessBoard(){
  59. for (i=0;i<12;i++){
  60. for(j=0;j<12;j++){
  61. pieces[i][j]='\0';
  62. }
  63. }
  64. pieces[2][2]= 'R';
  65. pieces[2][3]= 'N';
  66. pieces[2][4]= 'B';
  67. pieces[2][5]= 'Q';
  68. pieces[2][6]= 'K';
  69. pieces[2][7]= 'B';
  70. pieces[2][8]= 'N';
  71. pieces[2][9]= 'R';
  72.  
  73. pieces[9][2]= 'r';
  74. pieces[9][3]= 'n';
  75. pieces[9][4]= 'b';
  76. pieces[9][5]= 'q';
  77. pieces[9][6]= 'k';
  78. pieces[9][7]= 'b';
  79. pieces[9][8]= 'n';
  80. pieces[9][9]= 'r';
  81.  
  82. for(j=2;j<10;j++){
  83. pieces[3][j]= 'P';
  84. }
  85.  
  86. for(j=2;j<10;j++){
  87. pieces[8][j]= 'p';
  88. }
  89. }
  90.  
  91. void printGame (){
  92. for (i=0;i<12;i++){
  93. for (j=0;j<12;j++){
  94. printf("%c",gameBoard[i][j]);
  95. printf("%c ", pieces[i][j]);
  96. }
  97. printf("\n\n");
  98. }
  99. }
  100.  
  101. void swapElements (int swap[]){
  102. pieces[swap[1]][swap[0]]=pieces[swap[1]][swap[0]]^pieces[swap[3]][swap[2]];
  103. pieces[swap[3]][swap[2]]=pieces[swap[3]][swap[2]]^pieces[swap[1]][swap[0]];
  104. pieces[swap[1]][swap[0]]=pieces[swap[1]][swap[0]]^pieces[swap[3]][swap[2]];
  105. }
  106.  
  107. int main()
  108. {
  109. char pieces[12][12];
  110. char gameBoard [12][12];
  111. int i,j;
  112. startingChessBoard();
  113. gameBoardBorders();
  114. checkerBoard();
  115. printGame();
  116. char play[5];
  117. int swap[5];
  118. char temp;
  119. while (1){
  120. printf("Player1 : ");
  121. scanf("%s",play);
  122. swap[0]=play[0]-63;
  123. swap[1]=58-play[1];
  124. swap[2]=play[2]-63;
  125. swap[3]=58-play[3];
  126. swapElements(swap);
  127. printGame();
  128. }
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement