// kun.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include using namespace std; const int N = 8; int pole [N][N]; int zpetX [N][N]; int zpetY [N][N]; void skok (int x, int y, int i, int j, int k) { if (i >= 0 && i < N && j >= 0 && j < N) { if(pole[i][j] == -1 || pole [i][j] > k) { pole[i][j] = k; zpetX[i][j] = x; zpetY[i][j] = y; skok(i , j, i + 1, j + 2, k+1); skok(i , j, i + 2, j + 1, k+1); skok(i , j, i - 1, j - 2,k+1); skok(i , j, i - 2, j - 1,k+1); skok(i , j, i + 1, j - 2,k+1); skok(i , j, i + 2, j - 1,k+1); skok(i , j, i - 1, j + 2,k+1); skok(i , j, i - 2, j + 1,k+1); } } } void vypis(){ for (int i = 0; i < N ; i ++){ for (int j = 0; j < N ; j ++){ char c; int h=pole[i][j]; if (h >= 0 && h<=9) c= '0'+h; else if (h >= 10 && h<=35) c= 'a'+h-10; else if (h >= 36 && h<=61) c= 'A'+h-36; else if (h==-1) c='.'; else if (h==-2) c='@'; cout << c << " "; } cout << endl;}} void cesta(int i, int j) { int p,q; while(i>=0 && j>=0 ) { cout << i << " "<< j << endl; p = zpetX[i][j]; q = zpetY[i][j]; i=p; j=q; } } void cestazpet(int i, int j) { if(i>=0 && j>=0 ) { cout << i << " "<< j << endl; cestazpet(zpetX[i][j], zpetY[i][j]); } } void cestatam(int i, int j) { if(i>=0 && j>=0 ) { cestatam(zpetX[i][j], zpetY[i][j]); cout << i << " "<< j << endl; } } int _tmain(int argc, _TCHAR* argv[]) { for (int i = 0; i < N ; i ++) for (int j = 0; j < N ; j ++) { pole [i][j] = -1; zpetX [i][j] = -1; zpetY [i][j] = -1; } int i = 0; int j = 0; skok (-1, -1, i, j,0); vypis(); cout << "==========="<< endl; cesta(N-1,N-1); cout << "==========="<< endl; cestazpet(N-1,N-1); cout << "==========="<< endl; cestatam(N-1,N-1); system ("pause"); return 0; }