#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
 
const int n = 8;
int p[n][n];
int zx[n][n];
int zy[n][n];
 
void jump (int x, int y, int poradi, int x0, int y0)
{
    if (x >= 0 && x < n && y >= 0 && y < n)
    {
        if (p[x][y]==(-1)||p[x][y] > poradi)
        {
            p[x][y] = poradi;
            zx[x][y] = x0;
            zy[x][y] = y0;
            jump (x + 2, y + 1, poradi + 1, x, y);
            jump (x + 2, y - 1, poradi + 1, x, y);
            jump (x + 1, y + 2, poradi + 1, x, y);
            jump (x + 1, y - 2, poradi + 1, x, y);
            jump (x - 1, y + 2, poradi + 1, x, y);
            jump (x - 1, y - 2, poradi + 1, x, y);
            jump (x - 2, y + 1, poradi + 1, x, y);
            jump (x - 2, y - 1, poradi + 1, x, y);
        }
 
    }
}
 
void print (int x, int y) {
    if (x >= 0 && y >= 0) {    
        print (zx[x][y], zy[x][y]);
        cout << x << "," << y << endl;
    }
}
 
int main (int argc, char * argv [])
{
    for (int i = 0; i < n; i++)
        for (int k = 0; k < n; k++)
        {
            p[i][k] = -1;
            zx[i][k] = -1;
            zy[i][k] = -1;
        }
 
 
    int x = 0;
    int y = 0;
 
    jump (x, y, 0, -1, -1);
 
    for (int i = 0; i < n; i++)
    {
        for (int k = 0; k < n; k++)
        {
            if (p[i][k] < 0)
            {
                cout << ". ";
            }
            else
            {
                cout << p[i][k] << " ";
            }
 
        }
        cout << endl;
    }
 
    for (int i = 0; i < n; i++)
    {
        for (int k = 0; k < n; k++)
        {
            cout << "(" << zx[i][k] << "," << zy[i][k] << ")" << " ";
        }
        cout << endl;
    }
 
    print (n - 1, n - 1);
 
   /* x = n - 1;
    y = n - 1;
 
    while (x >= 0 && y >= 0) {
        cout << x << "," << y << endl;
        int x1 = zx[x][y];
        int y1 = zy[x][y];
        x = x1;
        y = y1;
    }
    */
 
 
    cout << "Konec programu" << endl;
    system ("pause");
    return 0;
}
 
kun_2018_ut.txt · Last modified: 2018/04/17 09:41 by 147.32.8.110
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki