#include int m[8][8]={ //j,y 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}, //i,x 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 (valgeid>0 || musti>0){ tryki(); olemas=0; while (olemas!=1){ if (k2ik==1){ printf("Valge k2ik! "); } else{ printf("Musta k2ik! "); } printf("Millist nuppu liigutame:"); fgets(kust, 4, stdin); //loeb stringina sisse i =(int)kust[0]-97; j = (int)kust[1]-49; if( m[j][i]>0){ //kontrollib, kas sellel aadressil asub nupp if(k2ik==1 && m[j][i]==1){ //kontrollib, kas käiakse õiget värvi nuppu olemas=1;} if(k2ik==2 && m[j][i]==2){ olemas=1;} if(k2ik!=m[j][i]){ printf("Kontrolli kelle k2ik on!\n");} } else { printf("Nuppu pole.\n"); }} uuesti: printf("Kuhu selle nupu k2ime:"); fgets(kuhu, 4, stdin); x =(int)kuhu[0]-97; y = (int)kuhu[1]-49; if ((x>=0 && x<=7)&&(y>=0 && y<=7)) //kas k2ik on laual { if((i-x!=-1 && i-x!=1)){ printf("K2ia saab ainult diagonaalis!\n"); goto again; } if((j-y!=-1 && j-y!=1)){ printf("K2ia saab ainult diagonaalis!\n"); goto again; } if(m[y][x]!=0){ printf("Teise nupu peale ei saa k2ia\n"); goto again;} m[y][x]=m[j][i]; m[j][i]=0; } else{ printf("K2isid laualt v2lja!!.\n"); } if (k2ik==1){ k2ik=2;} else { k2ik=1;} } return 0; }