#include #include void trykiMassiiv(int mas[8][8]); int liiguta_nuppu(int mas[8][8], int alg_x, int alg_y, int lopp_x, int lopp_y); char int_chariks (int input); // vajalik sisestamisel, et arvuti saaks aru, et a ja A on tegelikult 0 // b ja B tegelikult 1 jne int char_integeriks (int input); int main(void){ 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} }; char taht1, taht2, enter, tyhik; int number1, number2; while (taht1 != 'q'){ trykiMassiiv(m); scanf("%c%d%c%c%d%c", &taht1, &number1, &tyhik, &taht2, &number2, &enter); liiguta_nuppu(m, char_integeriks(taht1), number1-1, char_integeriks(taht2), number2-1); system("cls"); } return 0; } int char_integeriks (int ascii_kood){ int integer; if (ascii_kood==97) integer=0; if (ascii_kood==98) integer=1; if (ascii_kood==99) integer=2; if (ascii_kood==100) integer=3; if (ascii_kood==101) integer=4; if (ascii_kood==102) integer=5; if (ascii_kood==103) integer=6; if (ascii_kood==104) integer=7; if (ascii_kood == 65) integer=0; if (ascii_kood == 66) integer=1; if (ascii_kood == 67) integer=2; if (ascii_kood == 68) integer=3; if (ascii_kood == 69) integer=4; if (ascii_kood == 70) integer=5; if (ascii_kood == 71) integer=6; if (ascii_kood == 72) integer=7; return integer; } char int_chariks (int input){ char taht; if (input==0) taht = '°'; if (input==1) taht = '›'; if (input==2) taht = '˛'; if (input==3) taht = ' '; return taht; } int liiguta_nuppu(int mas[8][8], int alg_x, int alg_y, int lopp_x, int lopp_y){ int temp; if ( mas[alg_y][alg_x] == 0 || mas[alg_y][alg_x] == 3 ) return 0; // votame nupu ara if ( alg_y - lopp_y == 2 && alg_x - lopp_x == 2) mas[alg_y - 1][alg_x-1] = 3; if ( alg_y - lopp_y == 2 && alg_x + 2 == lopp_x) mas[alg_y - 1][alg_x+1] = 3; if ( alg_y + 2 == lopp_y && alg_x - 2 == lopp_x) mas[alg_y + 1][alg_x-1] = 3; if ( alg_y + 2 == lopp_y && alg_x + 2 == lopp_x) mas[alg_y + 1][alg_x+1] = 3; temp = mas[lopp_y][lopp_x]; mas[lopp_y][lopp_x] = mas[alg_y][alg_x]; mas[alg_y][alg_x] = temp; } void trykiMassiiv(int mas[8][8]){ int i,j; char k,q; printf("\n"); printf(" abcdefgh\n"); printf(" --------\n"); for(i=0; i<8; i++){ printf("%d ",i+1); printf("|"); for(j=0; j<8; j++){ printf ("%c", int_chariks(mas[i][j]) ); } printf("|"); printf(" %d",i+1); printf("\n"); } printf(" --------\n"); printf(" abcdefgh\n\n\n"); printf(" › on valged nupud\n"); printf(" ˛ on mustad nupud\n"); printf("sisestage tegevus (tähtnumber tähtnumber) :"); // scanf("%c", k); }