I have been working on this knight's tour recursion problem for days and still can't find a solution. Can someone help me identify the error? I've been searching for it for a long time and the maximum tiles it can fill up to is only 60. I have no idea what the error is. Here is my code:
#include <iostream>;
#include <string>;
#include <vector>;
#include <cstdlib>;
#include <cmath>;
#include <ctype.h>;
#include <ctime>;
#include <stdlib.h>;
using namespace std;
int step=1, v[8][8], x[8], y[8];
bool success;
bool SolveKnightTour(int step, int xc, int yc){
if (step>64){
success=true;
}
else {
success=false;
int move=0;
while(move<8 & success==false){
if (xc+x[move]>=0 & xc+x[move]<8 & yc+y[move]>=0 & yc+y[move]<8 & v[yc+y[move]][xc+x[move]]==0){
v[yc+y[move]][xc+x[move]]=step+1;
if (!SolveKnightTour(step+1, xc+x[move], yc+y[move])){
v[yc+y[move]][xc+x[move]]=0;
}
}
if (success==false){
move++;
}
}
}
return success;
}
int main(){
int i, j;
x[0]=1, y[0]=-2;
x[1]=2, y[1]=-1;
x[2]=2, y[2]=1;
x[3]=1, y[3]=2;
x[4]=-1, y[4]=2;
x[5]=-2, y[5]=1;
x[6]=-2, y[6]=-1;
x[7]=-1, y[7]=-2;
for (i=0;i<8;i++){
for (j=0;j<8;j++){
v[i][j]=0;
}
}
v[4][4]=1;
SolveKnightTour(step, 4, 4);
for (i=0;i<8;i++){
for (j=0;j<8;j++){
cout<<v[i][j]<<" ";
}
cout<<"\n";
}
system("pause");
return 0;
}
Any help is greatly appreciated.