Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- char pieces[12][12];
- char gameBoard [12][12];
- int i,j;
- void gameBoardBorders(){
- for (i=0;i<12;i++){
- for (j=0;j<12;j++){
- gameBoard[i][j]='\0';
- }
- }
- for (i=0;i<12;i+=11){
- for (j=2;j<10;j++){
- gameBoard[i][j]='A'+(j-2);
- }
- }
- for (j=2;j<10;j++){
- gameBoard[1][j]='-';
- gameBoard[10][j]='-';
- }
- for (i=2;i<10;i++){
- for (j=0;j<12;j+=11){
- gameBoard[i][j]='8'-(i-2);
- }
- }
- for (i=2;i<10;i++){
- gameBoard[i][1]='|';
- gameBoard[i][10]='|';
- }
- }
- void checkerBoard(){
- for (i=2;i<10;i++){
- for (j=2;j<10;j+=2){
- if (i%2==0){
- gameBoard[i][j]='.';
- }
- else {
- gameBoard[i][j]='+';
- }
- }
- }
- for (i=2;i<10;i++){
- for (j=3;j<10;j+=2){
- if (i%2==0){
- gameBoard[i][j]='+';
- }
- else {
- gameBoard[i][j]='.';
- }
- }
- }
- }
- void startingChessBoard(){
- for (i=0;i<12;i++){
- for(j=0;j<12;j++){
- pieces[i][j]='\0';
- }
- }
- pieces[2][2]= 'R';
- pieces[2][3]= 'N';
- pieces[2][4]= 'B';
- pieces[2][5]= 'Q';
- pieces[2][6]= 'K';
- pieces[2][7]= 'B';
- pieces[2][8]= 'N';
- pieces[2][9]= 'R';
- pieces[9][2]= 'r';
- pieces[9][3]= 'n';
- pieces[9][4]= 'b';
- pieces[9][5]= 'q';
- pieces[9][6]= 'k';
- pieces[9][7]= 'b';
- pieces[9][8]= 'n';
- pieces[9][9]= 'r';
- for(j=2;j<10;j++){
- pieces[3][j]= 'P';
- }
- for(j=2;j<10;j++){
- pieces[8][j]= 'p';
- }
- }
- void printGame (){
- for (i=0;i<12;i++){
- for (j=0;j<12;j++){
- printf("%c",gameBoard[i][j]);
- printf("%c ", pieces[i][j]);
- }
- printf("\n\n");
- }
- }
- void swapElements (int swap[]){
- pieces[swap[1]][swap[0]]=pieces[swap[1]][swap[0]]^pieces[swap[3]][swap[2]];
- pieces[swap[3]][swap[2]]=pieces[swap[3]][swap[2]]^pieces[swap[1]][swap[0]];
- pieces[swap[1]][swap[0]]=pieces[swap[1]][swap[0]]^pieces[swap[3]][swap[2]];
- }
- int main()
- {
- char pieces[12][12];
- char gameBoard [12][12];
- int i,j;
- startingChessBoard();
- gameBoardBorders();
- checkerBoard();
- printGame();
- char play[5];
- int swap[5];
- char temp;
- while (1){
- printf("Player1 : ");
- scanf("%s",play);
- swap[0]=play[0]-63;
- swap[1]=58-play[1];
- swap[2]=play[2]-63;
- swap[3]=58-play[3];
- swapElements(swap);
- printGame();
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment