#include enum{bWhite,bBlack,bFree,bOff}; int m[8][8]={ {bWhite, bOff, bWhite, bOff, bWhite, bOff, bWhite, bOff }, {bOff, bWhite, bOff, bWhite, bOff, bWhite, bOff, bWhite }, {bWhite, bOff, bWhite, bOff, bWhite, bOff, bWhite, bOff }, {bOff, bFree, bOff, bFree, bOff, bFree, bOff, bFree }, {bFree, bOff, bFree, bOff, bFree, bOff, bFree, bOff }, {bOff, bBlack, bOff, bBlack, bOff, bBlack, bOff, bBlack }, {bBlack, bOff, bBlack, bOff, bBlack, bOff, bBlack, bOff }, {bOff, bBlack, bOff, bBlack, bOff, bBlack, bOff, bBlack }, }; int ValjastaKabeLaud(){ int i,j; printf(" A B C D E F G H\n"); printf("\n"); for(i=0; i<8; i++){ printf("%d ",i+1); for(j=0; j<8; j++){ switch(m[i][j]){ case bOff: printf("%c%c", 177,177); break; case bFree: printf(" "); break; case bBlack: printf("X "); break; case bWhite: printf("Y "); break; default: printf(" %d", m[i][j] ); } } printf("\n"); } printf(" A B C D E F G H\n"); printf("\n"); } int main(void){ char taht, tahtkuhu, enter, tuhik; int koodkust=(int)taht; int koodkuhu=(int)tahtkuhu; int i,j,nupud=24,kord=1; int arv1,arv2,arvkuhu1,arvkuhu2; ValjastaKabeLaud(); while(nupud>1 ){ if(kord==1 ){ printf("Valge kord on liikuda!\n"); printf("\n"); } else { printf("Musta kord on liikuda!\n"); printf("\n"); } printf("Milliselt ruudult Sa alustada soovid ja kuhu?: "); scanf("%c%d%c%c%d%c", &taht, &arv2, &tuhik, &tahtkuhu, &arvkuhu2,&enter); if(taht=='q') break; koodkust=(int)taht; //tekst acii kood koodkuhu=(int)tahtkuhu; //tekstkuhu acii kood arv1=koodkust-97; arvkuhu1=koodkuhu-97; arv2=arv2-1; arvkuhu2=arvkuhu2-1; if(arvkuhu2-(arv2)==0 || (arvkuhu1)-(arv1)==0 || m[arvkuhu2][arvkuhu1]==0){ printf("\n"); printf("See liigutus pole lubatud!\n"); printf("\n"); } else { if(arvkuhu2-arv2==1||-1 || arvkuhu1-arv1==1||-1 || m[arv2][arv1]==bWhite||bBlack) { if(arvkuhu2-arv2==2 || arvkuhu1-arv1==2 || arvkuhu2-arv2==-2 || arvkuhu1-arv1==-2) { //kontroll kas tahad nupu ära võtta, põhjustab väga imelikke asju veel nupud=nupud-1; /*printf ("%d\n" ,m[arvkuhu1-1][arvkuhu2-1]); printf ("arvkuhu2 ""%d\n" ,arvkuhu2); printf ("arvkuhu1 ""%d\n" ,arvkuhu1);*/ if(arvkuhu2-arv2==2 && arvkuhu1-arv1==2){m[arvkuhu2-1][arvkuhu1-1]=bFree;}// nupukoristus töötab juhul kui valge võtab paremale -1/-1; if(arvkuhu2-arv2==2 && arvkuhu1-arv1==-2){m[arvkuhu2-1][arvkuhu1+1]=bFree;}//valge vasakule if(arvkuhu2-arv2==-2 && arvkuhu1-arv1==2){m[arvkuhu2+1][arvkuhu1-1]=bFree;}//must paremale if(arvkuhu2-arv2==-2 && arvkuhu1-arv1==-2){m[arvkuhu2+1][arvkuhu1+1]=bFree;}//must vasakule if(kord==1){ printf("\n"); printf("Eemaldas valge nupu"); printf("\n"); }else{ if(kord==2){ printf("\n"); printf("Eemaldas musta nupu"); printf("\n"); /*printf ("%d\n" ,m[arvkuhu1-1][arvkuhu2-1]); printf ("%d\n" ,arvkuhu2-arv2); printf ("%d\n" ,arvkuhu1-arv1);*/ } } } m[arvkuhu2][arvkuhu1]=m[arv2][arv1]; m[arv2][arv1]=bFree; printf("\n"); printf("Muudatus tehtud\n"); if(kord==1 ){ kord=2 ; } else { kord=1; } } else { printf("Käik pole lubatud\n"); } } printf("\n"); ValjastaKabeLaud(); } return 0; }