Backtracking/Knight tour problem/c/knight_tour_problem.c
/* This function solves the Knight Tour problem using 
   Backtracking.  This function mainly uses solveKTUtil() 
   to solve the problem. It returns false if no complete 
   tour is possible, otherwise return true and prints the 
   tour. 
   Please note that there may be more than one solutions, 
   this function prints one of the feasible solutions.  */
This function solves the Knight Tour problem using
Backtracking.  This function mainly uses solveKTUtil()
to solve the problem. It returns false if no complete
tour is possible, otherwise return true and prints the
tour.
Please note that there may be more than one solutions,
this function prints one of the feasible solutions.
This function solves the Knight Tour problem using Backtracking . This function mainly uses solveKTUtil () to solve the problem . It returns false if no complete tour is possible otherwise return true and prints the tour . Please note that there may be more than one solutions this function prints one of the feasible solutions .
bool solveKT() 
{ 
    int sol[N][N]; 
    for (int x = 0; x < N; x++) 
        for (int y = 0; y < N; y++) 
            sol[x][y] = -1; 
    int xMove[8] = {  2, 1, -1, -2, -2, -1,  1,  2 }; 
    int yMove[8] = {  1, 2,  2,  1, -1, -2, -2, -1 }; 
    sol[0][0]  = 0; 
    if (solveKTUtil(0, 0, 1, sol, xMove, yMove) == false) 
    { 
        printf("Solution does not exist"); 
        return false; 
    } 
    else
        printSolution(sol); 
    return true; 
}
bool solveKT ( ) { int sol [ N ] [ N ] ; for ( int x = 0 ; x < N ; x ++ ) for ( int y = 0 ; y < N ; y ++ ) sol [ x ] [ y ] = -1 ; int xMove [ 8 ] = { 2 , 1 , -1 , -2 , -2 , -1 , 1 , 2 } ; int yMove [ 8 ] = { 1 , 2 , 2 , 1 , -1 , -2 , -2 , -1 } ; sol [ 0 ] [ 0 ] = 0 ; if ( solveKTUtil ( 0 , 0 , 1 , sol , xMove , yMove ) == false ) { printf ( " " ) ; return false ; } else printSolution ( sol ) ; return true ; }
This function solves the Knight Tour problem using
Backtracking.
This function solves the Knight Tour problem using Backtracking .
/* Initialization of solution matrix */ /* xMove[] and yMove[] define next move of Knight. 
       xMove[] is for next value of x coordinate 
       yMove[] is for next value of y coordinate */ // Since the Knight is initially at the first block  /* Start from 0,0 and explore all tours using 
       solveKTUtil() */