fork download
  1. #include "checkers.h"
  2.  
  3. void print_board()
  4. {
  5. int i,j;
  6. for (i=0;i<8;i++){ /*Prints the numbers on top row*/
  7. printf(" %d", i);
  8. }
  9. printf("\n");
  10.  
  11. /*Prints grid. If the_board = 0, prints " ", if the_board = 1, prints "r"...*/
  12. for(i=0;i<BOARD_SIZE; i++){
  13. printf(" |---|---|---|---|---|---|---|---|\n");
  14. printf("%d| ",i); /*Prints numbers on left side*/
  15. for(j=0;j<BOARD_SIZE;j++){
  16. switch (the_board[i][j]){
  17. case 0:
  18. printf(" ");
  19. break;
  20. case 1:
  21. printf("r");
  22. break;
  23. case 2:
  24. printf("w");
  25. break;
  26. case 3:
  27. printf("R");
  28. break;
  29. case 4:
  30. printf("W");
  31. break;
  32. }
  33. printf(" | ");
  34. }
  35. printf("\n");
  36. }
  37. printf(" |---|---|---|---|---|---|---|---|\n");
  38. }
  39.  
  40. int checkBounds(int input1, int input2, int input3, int input4){
  41. if ( ( input1 >= BOARD_SIZE) || (input2 >= BOARD_SIZE) || (input3 >= BOARD_SIZE)|| (input4 >= BOARD_SIZE) || ( input1 < 0) || (input2 < 0) || (input3 < 0)|| (input4 < 0)){
  42. return 8888;
  43. }
  44. }
  45.  
  46. int changePlayer(){
  47. if (currentPlayer==redTurn){
  48. currentPlayer=whiteTurn;
  49. }else{
  50. currentPlayer=redTurn;
  51. }
  52. }
  53.  
  54. int printPlayer(){
  55. switch (currentPlayer){
  56. case 91:
  57. printf("White's Move: ");
  58. break;
  59. case 93:
  60. printf("Red's Move: ");
  61. break;
  62. }
  63. }
  64.  
  65. int checkPlayerPiece(){
  66. if(currentPlayer == whiteTurn && ( (the_board [y_from][x_from]==WHITE) || (the_board [y_from][x_from]==WHITE_KING)) ){
  67. return VALID_MOVE;
  68. }else if(currentPlayer == redTurn && ( (the_board [y_from][x_from]==RED) || (the_board [y_from][x_from]==RED_KING)) ){
  69. return VALID_MOVE;
  70. }else{
  71. return INVALID_MOVE;}
  72. }
  73.  
  74. int movePiece() {
  75. the_board [y_to][x_to] = the_board[y_from][x_from];
  76. the_board [y_from][x_from]= 0;
  77. print_board();
  78. }
  79.  
  80. int is_jumper(int x, int y){
  81.  
  82. if(the_board[y][x] == RED && (((the_board[y+1][x+1] == WHITE || the_board[y+1][x+1]== WHITE_KING) && the_board[y+2][x+2] == 0) || ((the_board[y+1][x-1] == WHITE ||the_board[y+1][x-1] == WHITE_KING ) && the_board[y+2][x-2]== 0 && (y+2<= BOARD_SIZE) && (x-2 >= 0)))){
  83. return TRUE;
  84. }else if( the_board[y][x] == WHITE && ((((the_board[y-1][x-1]==RED || the_board[y-1][x-1]==RED_KING) && the_board[y-2][x-2]==0 && (x-2>=0)) || (((the_board[y-1][x+1]==RED )|| the_board[y-1][x+1]==RED_KING) && the_board[y-2][x+2]==0 && (x+2 <= BOARD_SIZE) )) && (y-2>=0))){
  85. return TRUE;
  86. }else if(the_board[y][x]==RED_KING && (((the_board[y+1][x+1]==WHITE || the_board[y+1][x+1]==WHITE_KING) && the_board[y+2][x+2]==0 ) || ((the_board[y+1][x-1]==WHITE || the_board[y+1][x-1]==WHITE_KING) && the_board[y+2][x-2]==0)) && (y+2 <BOARD_SIZE) && (x+2 <BOARD_SIZE) && (y-2 >=0) && (x-2 >=0)){
  87. return TRUE;
  88. }else if (the_board[y][x]==WHITE_KING && ((((the_board[y+1][x+1]==RED || the_board[y+1][x+1]==RED_KING) && the_board[y+2][x+2]==0 ) || ((the_board[y+1][x-1]==RED || the_board[y+1][x-1]==RED_KING) && the_board[y+2][x-2]==0))) && (y+2 <BOARD_SIZE) && (x+2 <BOARD_SIZE) && (y-2 >=0) && (x-2 >=0)){
  89. return TRUE;
  90. }else{
  91. return 0;
  92. }
  93. }
  94.  
  95. int check_move(int color, int x_from, int y_fromt, int x_to, int y_to, int jump){
  96.  
  97. int dir;
  98.  
  99. if (color==whiteTurn){
  100. dir = 1;
  101. }else if(color==redTurn){
  102. dir = -1;
  103. }
  104.  
  105. if (checkBounds(x_from, y_from, x_to, y_to) == 8888 ){
  106. return INVALID_MOVE;
  107. }else if(the_board[y_to][x_to]!= 0){
  108. return INVALID_MOVE;
  109. }else if(checkPlayerPiece() != VALID_MOVE ){
  110. return INVALID_MOVE;
  111. }else if( check_step(x_from, y_from, x_to, y_to, dir)!= VALID_MOVE ){
  112. return INVALID_MOVE;
  113. }else
  114. return VALID_MOVE;
  115. }
  116.  
  117. int check_step(int x_from, int y_from, int x_to, int y_to, int dir){
  118.  
  119. switch(dir){
  120.  
  121. case -1:
  122. if( ((y_to-y_from)== 1 && (x_to-x_from)== 1 ) || ((y_to-y_from)== 1 && (x_to-x_from)== -1 ) ){
  123. return VALID_MOVE;
  124. }else{
  125. return INVALID_MOVE;
  126. }
  127. case 1:
  128. if( ((y_to-y_from)== -1 && (x_to-x_from)== 1 ) || ((y_to-y_from)== -1 && (x_to-x_from)== -1 ) ){
  129. return VALID_MOVE;
  130. }else{
  131. return INVALID_MOVE;
  132. }
  133. }
  134. }
  135.  
  136. void move_piece(int color, int x_from, int y_from, int x_to, int y_to, int jump){
  137. if (jump == 0){
  138. the_board [y_to][x_to] = the_board[y_from][x_from];
  139. the_board [y_from][x_from]= 0;
  140. }
  141. }
  142.  
  143. int jump_exists(int color){
  144.  
  145. int i,j;
  146.  
  147. if (color==WHITE){
  148. for(i=0;i < BOARD_SIZE; i++){
  149. for(j=0;i <BOARD_SIZE; j++){
  150. if((the_board[i][j]==WHITE || (the_board[i][j]==WHITE_KING) && (is_jump(j,i) == 1))){
  151. printf("YOU CAN JUMP %d %d",i,j);
  152. return TRUE;
  153. }
  154. }
  155. }
  156. }else if(color==RED){
  157. for(i=0;i < BOARD_SIZE; i++){
  158. for(j=0;i <BOARD_SIZE; j++){
  159. if((the_board[i][j]==RED || (the_board[i][j]==RED_KING) && (is_jump(j,i) == 1))){
  160. printf("YOU CAN JUMP %d %d",i,j);
  161. return TRUE;
  162. }
  163. }
  164. }
  165. }
  166. }
  167.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:22: error: checkers.h: No such file or directory
prog.cpp: In function ‘void print_board()’:
prog.cpp:7: error: ‘printf’ was not declared in this scope
prog.cpp:9: error: ‘printf’ was not declared in this scope
prog.cpp:12: error: ‘BOARD_SIZE’ was not declared in this scope
prog.cpp:16: error: ‘the_board’ was not declared in this scope
prog.cpp: In function ‘int checkBounds(int, int, int, int)’:
prog.cpp:41: error: ‘BOARD_SIZE’ was not declared in this scope
prog.cpp: In function ‘int changePlayer()’:
prog.cpp:47: error: ‘currentPlayer’ was not declared in this scope
prog.cpp:47: error: ‘redTurn’ was not declared in this scope
prog.cpp:48: error: ‘whiteTurn’ was not declared in this scope
prog.cpp: In function ‘int printPlayer()’:
prog.cpp:55: error: ‘currentPlayer’ was not declared in this scope
prog.cpp:57: error: ‘printf’ was not declared in this scope
prog.cpp: In function ‘int checkPlayerPiece()’:
prog.cpp:66: error: ‘currentPlayer’ was not declared in this scope
prog.cpp:66: error: ‘whiteTurn’ was not declared in this scope
prog.cpp:66: error: ‘the_board’ was not declared in this scope
prog.cpp:66: error: ‘y_from’ was not declared in this scope
prog.cpp:66: error: ‘x_from’ was not declared in this scope
prog.cpp:66: error: ‘WHITE’ was not declared in this scope
prog.cpp:66: error: ‘WHITE_KING’ was not declared in this scope
prog.cpp:67: error: ‘VALID_MOVE’ was not declared in this scope
prog.cpp:68: error: ‘redTurn’ was not declared in this scope
prog.cpp:68: error: ‘RED’ was not declared in this scope
prog.cpp:68: error: ‘RED_KING’ was not declared in this scope
prog.cpp:69: error: ‘VALID_MOVE’ was not declared in this scope
prog.cpp:71: error: ‘INVALID_MOVE’ was not declared in this scope
prog.cpp: In function ‘int movePiece()’:
prog.cpp:75: error: ‘the_board’ was not declared in this scope
prog.cpp:75: error: ‘y_to’ was not declared in this scope
prog.cpp:75: error: ‘x_to’ was not declared in this scope
prog.cpp:75: error: ‘y_from’ was not declared in this scope
prog.cpp:75: error: ‘x_from’ was not declared in this scope
prog.cpp: In function ‘int is_jumper(int, int)’:
prog.cpp:82: error: ‘the_board’ was not declared in this scope
prog.cpp:82: error: ‘RED’ was not declared in this scope
prog.cpp:82: error: ‘WHITE’ was not declared in this scope
prog.cpp:82: error: ‘WHITE_KING’ was not declared in this scope
prog.cpp:82: error: ‘BOARD_SIZE’ was not declared in this scope
prog.cpp:83: error: ‘TRUE’ was not declared in this scope
prog.cpp:84: error: ‘RED_KING’ was not declared in this scope
prog.cpp:85: error: ‘TRUE’ was not declared in this scope
prog.cpp:87: error: ‘TRUE’ was not declared in this scope
prog.cpp:89: error: ‘TRUE’ was not declared in this scope
prog.cpp: In function ‘int check_move(int, int, int, int, int, int)’:
prog.cpp:99: error: ‘whiteTurn’ was not declared in this scope
prog.cpp:101: error: ‘redTurn’ was not declared in this scope
prog.cpp:105: error: ‘y_from’ was not declared in this scope
prog.cpp:106: error: ‘INVALID_MOVE’ was not declared in this scope
prog.cpp:107: error: ‘the_board’ was not declared in this scope
prog.cpp:108: error: ‘INVALID_MOVE’ was not declared in this scope
prog.cpp:109: error: ‘VALID_MOVE’ was not declared in this scope
prog.cpp:110: error: ‘INVALID_MOVE’ was not declared in this scope
prog.cpp:111: error: ‘check_step’ was not declared in this scope
prog.cpp:112: error: ‘INVALID_MOVE’ was not declared in this scope
prog.cpp: In function ‘int check_step(int, int, int, int, int)’:
prog.cpp:123: error: ‘VALID_MOVE’ was not declared in this scope
prog.cpp:125: error: ‘INVALID_MOVE’ was not declared in this scope
prog.cpp:129: error: ‘VALID_MOVE’ was not declared in this scope
prog.cpp:131: error: ‘INVALID_MOVE’ was not declared in this scope
prog.cpp: In function ‘void move_piece(int, int, int, int, int, int)’:
prog.cpp:138: error: ‘the_board’ was not declared in this scope
prog.cpp: In function ‘int jump_exists(int)’:
prog.cpp:147: error: ‘WHITE’ was not declared in this scope
prog.cpp:148: error: ‘BOARD_SIZE’ was not declared in this scope
prog.cpp:150: error: ‘the_board’ was not declared in this scope
prog.cpp:150: error: ‘WHITE_KING’ was not declared in this scope
prog.cpp:150: error: ‘is_jump’ was not declared in this scope
prog.cpp:151: error: ‘printf’ was not declared in this scope
prog.cpp:152: error: ‘TRUE’ was not declared in this scope
prog.cpp:156: error: ‘RED’ was not declared in this scope
prog.cpp:157: error: ‘BOARD_SIZE’ was not declared in this scope
prog.cpp:159: error: ‘the_board’ was not declared in this scope
prog.cpp:159: error: ‘RED_KING’ was not declared in this scope
prog.cpp:159: error: ‘is_jump’ was not declared in this scope
prog.cpp:160: error: ‘printf’ was not declared in this scope
prog.cpp:161: error: ‘TRUE’ was not declared in this scope
stdout
Standard output is empty