//all i want to do here is zachytat board// #include #include #include void readboard(char); void nextmove(char arr[8][8],char turn, int i, int j); void print_board(char arr[8][8]); char arr[8][8]; void main() { char choice,t,turn; int i, j; printf("\nPlease enter a c for checkers or t for tic-tac-toe \n"); scanf("%c",&choice); if(choice=='c') readboard(t); else exit(1); printf("enter R for ""RED PIECE"" and W for ""WHITE PIECE""\n"); scanf(" %c",&turn); printf("you entered %c\n",turn); getchar(); for(i=0;i<=7;i++) for(j=0;j<=7;j++) nextmove(arr,turn,i,j); printf("\nPress enter to exit..."); getchar(); getchar(); exit(1); } void readboard(char t) { int i,j; printf("\nenter a board 8 lines by 8 characters, either R,W,O,P,V or -\n"); printf("after each line hit enter\n"); printf("enter a board\n\n"); for(i=0;i<=7;i++) for(j=0;j<=7;j++){ scanf(" %c",&arr[i][j]);//x, o or - from input are stored //in two-dimentional array } printf("\n"); printf("this is a board\n\n"); print_board(arr); } void nextmove(char arr[8][8],char turn,int i, int j){ if(arr[i][j]=='R' && turn=='R') { if(j&&(i<7)){ if(arr[i+1][j-1]=='-') //move R down and left { if(i+1<7) arr[i+1][j-1]='R'; else arr[i+1][j-1]='P'; arr[i][j]='-'; printf("\nPossible result from i=%d j=%d\n",i,j); print_board(arr); getchar(); arr[i+1][j-1]='-'; arr[i][j]='R'; } if(arr[i+1][j-1]=='W' && (i+2<8) && (j-2>=0) && arr[i+2][j-2]=='-') { //take W down and right if(i+2<7) arr[i+2][j-2]='R'; else arr[i+2][j-2]='P'; arr[i+1][j-1]='-'; arr[i][j]='-'; printf("\nPossible result from i=%d j=%d\n",i,j); print_board(arr); getchar(); arr[i+1][j-1]='W'; arr[i][j]='R'; arr[i+2][j-2]='-'; } } if(i<7&&j<7){ if(arr[i+1][j+1]=='-') { if(i+1<7) arr[i+1][j+1]='R'; //move R down and right else arr[i+1][j+1]='P'; arr[i][j]='-'; printf("\nPossible result from i=%d j=%d\n",i,j); print_board(arr); getchar(); arr[i+1][j+1]='-'; arr[i][j]='R'; } if(arr[i+1][j+1]=='W' && (i+2<8) && (j+2<8) && arr[i+2][j+2]=='-') { //take W down and right if(i+2<7) arr[i+2][j+2]='R'; else arr[i+2][j+2]='P'; arr[i+1][j+1]='-'; arr[i][j]='-'; printf("\nPossible result from i=%d j=%d\n",i,j); print_board(arr); getchar(); arr[i+1][j+1]='W'; arr[i][j]='R'; arr[i+2][j+2]='-'; } } } if(arr[i][j]=='W' && turn=='W') { if(j&&i){ if(arr[i-1][j-1]=='-') { if(i-1>0) arr[i-1][j-1]='W'; else arr[i-1][j-1]='V'; arr[i][j]='-'; printf("\nPossible result from i=%d j=%d\n",i,j); print_board(arr); getchar(); arr[i-1][j-1]='-'; arr[i][j]='W'; } } if(i&&j<7){ if(arr[i-1][j+1]=='-') { if(i-1>0) arr[i-1][j+1]='W'; else arr[i-1][j+1]='V'; arr[i][j]='-'; printf("\nPossible result from i=%d j=%d\n",i,j); print_board(arr); getchar(); arr[i-1][j+1]='-'; arr[i][j]='W'; } } } } void print_board(char arr[8][8]){ int i,j; for(i=0;i<=7;i++){ for(j=0;j<=7;j++) printf("%c",arr[i][j]); printf(" %d\n",i); } }