#include int m[8][8]= { {0, 1, 0, 1, 0, 1, 0, 1 }, {1, 0, 1, 0, 1, 0, 1, 0 }, {0, 1, 0, 1, 0, 1, 0, 1 }, {3, 0, 3, 0, 3, 0, 3, 0 }, {0, 3, 0, 3, 0, 3, 0, 3 }, {2, 0, 2, 0, 2, 0, 2, 0 }, {0, 2, 0, 2, 0, 2, 0, 2 }, {2, 0, 2, 0, 2, 0, 2, 0 } }; int ValjastaKabeLaud(){ int i,j; printf("V-valge nupp ja M-must nupp\n"); printf(" A B C D E F G H\n\n"); for(i=0; i<8; i++){ printf("%d ",i+1); for(j=0; j<8; j++){ switch(m[i][j]){ case 3: printf("%c%c", 255, 255); break; case 0: printf("%c%c", 177, 177); break; case 1: printf(" M"); break; case 2: printf(" V"); break; default: printf(" %d", m[i][j]); } } printf("\n"); } printf(" \n A B C D E F G H\n"); printf("\n"); } int main(void){ char t2ht, t2htkuhu, enter, tyhik; int koodkust=(int)t2ht; int koodkuhu=(int)t2htkuhu; int i,j,nupud=24,kord=1; int arv1,arv2,arvkuhu1,arvkuhu2; ValjastaKabeLaud(); while (nupud>=1){ if(kord==1){ printf("Valge k2ik\n"); } else { printf("Musta k2ik\n"); } printf("Tee oma k2ik: "); scanf("%c%d%c%c%d%c", &t2ht, &arv2, &tyhik, &t2htkuhu, &arvkuhu2,&enter); if (t2ht=='q')break; koodkust=(int)t2ht; //tekst acii kood koodkuhu=(int)t2htkuhu; //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("Nii ei saa k2ia!\n"); printf("\n"); } else { if(arvkuhu2-arv2==1||-1 || arvkuhu1-arv1==2||-1 || m[arv2][arv1]==2||1) { if(arvkuhu2-arv2==2 || arvkuhu1-arv1==2 || arvkuhu2-arv2==-2 || arvkuhu1-arv1==-2) { //sundv6tmine nupud=nupud-1; if(arvkuhu2-arv2==2 && arvkuhu1-arv1==2){m[arvkuhu2-1][arvkuhu1-1]=3 , printf("\n Valge nupp 2ra v6etud \n");}// valge v6tab paremale if(arvkuhu2-arv2==2 && arvkuhu1-arv1==-2){m[arvkuhu2-1][arvkuhu1+1]=3 , printf("\n Valge nupp 2ra v6etud \n");}//valge vasakule if(arvkuhu2-arv2==-2 && arvkuhu1-arv1==2){m[arvkuhu2+1][arvkuhu1-1]=3 , printf("\n Must nupp 2ra v6etud \n");}//must paremale if(arvkuhu2-arv2==-2 && arvkuhu1-arv1==-2){m[arvkuhu2+1][arvkuhu1+1]=3 , printf("\n Must nupp 2ra v6etud \n");}//must vasakule } m[arvkuhu2][arvkuhu1]=m[arv2][arv1]; m[arv2][arv1]=3; printf("\n"); printf("K2ik tehtud\n"); if(kord==1 ){ kord=2 ; } else { kord=1; } } else { printf("Nii ei saa k2ia!\n"); } } printf("\n"); ValjastaKabeLaud(); } return 0; }