#include //selle programmi autor on Kristjan :) int m[8][8]={ //i,x veerud {0, 1, 0, 1, 0, 1, 0, 1}, {1, 0, 1, 0, 1, 0, 1, 0}, {0, 1, 0, 1, 0, 1, 0, 1}, //j,y read {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {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 tryki() { 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++){ printf(" %d", m[i][j]); } printf("\n"); } return 0; } int main(void){ char kust[3], kuhu[3]; int i, j, x, y, olemas,k2ik=1; int valgeid=12, musti=12; while (1==1){ //loputu tsykkel printf("\nValgeid: %d Musti: %d\n\n",valgeid,musti); tryki(); olemas=0; while (olemas!=1){ if (k2ik==1){ printf("Valge k2ik! "); } else{ printf("Musta k2ik! "); } printf("Millist nuppu liigutame:"); fgets(kust, 4, stdin); i =(int)kust[0]-97; j = (int)kust[1]-49; if( m[j][i]>0){ //kas sellel aadressil asub nupp if(k2ik==1 && m[j][i]==1){ //kontroll, kas käiakse õiget värvi nuppu olemas=1;} if(k2ik==2 && m[j][i]==2){ olemas=1;} if(k2ik!=m[j][i]){ printf("valet v2rvi nupu sisestasid!\n");} } else { printf("Viga! Nuppu pole.\n"); } } uuesti: printf("Kuhu selle nupu t6stame:"); fgets(kuhu, 4, stdin); x =(int)kuhu[0]-97; y = (int)kuhu[1]-49; /*printf("y on %d\n", y); printf("j on %d\n", j); printf("x on %d\n", x);*/ //printf("i on %d ja j-y on %d\n", i, j-y); if ((x>=0 && x<=7)&&(y>=0 && y<=7)) //kas k2ik on laual { if(m[y][x]!=0){ printf("Teise nupu peale ei saa k2ia\n"); goto uuesti; } //printf("x-i: %d y-j: %d vaheruut: %d\n",x-i, y-j, m[j+1][i+1]); if((x-i==2)&&(y-j==2)&& m[j+1][i+1]!=0){ m[j+1][i+1]=0; //ylevalt paremale m[y][x]=m[j][i]; m[j][i]=0; olemas=2; if (k2ik==1){ musti=musti-1;} else{valgeid=valgeid-1;} } if((x-i==-2)&&(y-j==2)&& m[j+1][i-1]!=0){ m[j+1][i-1]=0; m[y][x]=m[j][i]; //ylevalt vasakule m[j][i]=0; olemas=2; if (k2ik==1){ musti=musti-1;} else{valgeid=valgeid-1;} } if((x-i==2)&&(y-j==-2)&& m[j-1][i+1]!=0){ m[j-1][i+1]=0; m[y][x]=m[j][i]; //alt paremale m[j][i]=0; olemas=2; if (k2ik==1){ musti=musti-1;} else{valgeid=valgeid-1;} } if((x-i==-2)&&(y-j==-2)&& m[j-1][i-1]!=0){ m[j-1][i-1]=0; m[y][x]=m[j][i]; //alt vasakule m[j][i]=0; olemas=2; if (k2ik==1){ musti=musti-1;} else{valgeid=valgeid-1;} } if((i-x==-1 || i-x==1)&&(j-y==-1 || j-y==1)){ m[y][x]=m[j][i]; m[j][i]=0; olemas=2; } //printf("%d\n",olemas); if (olemas==1){ printf("K2ia saab ainult diagonaalis!\n"); goto uuesti;} } else{ printf("K2ik on laualt v2ljas! Proovib uuesti.\n"); goto uuesti; } if (k2ik==1){ k2ik=2;} else { k2ik=1;} //printf("V: %d M: %d\n",valgeid, musti); if (musti==0){ break;} if (valgeid==0){ break;} } printf("\n- G A M E - O V E R -\n"); if (valgeid>musti){ printf("Valged v6itsid!!!\n");} else{printf("Mustad v6itsid");} return 0; }