Hey guys so i'm absolutely stuck trying to figure out the Knight's Tour problem(If you're not familiar with what this is just google it). We are supposed to use a recursive function to have the knight travel to legal places on the board. The function is: bool voyagingKnight(chessboard,i,j,step) where chessboard is the grid created using a vector of vectors, i and j are the cell position of the piece, and step is what number move the piece is on currently. To check where this piece can move we need to make a function called getMoves(i,j) which based off the cell position (i,j) it returns legal possible moves the knight can make. So i'm imagining this is a vital piece of code for this recursive function. I think that the getMoves function would check a list of possible moves the knight could make by checking to see if palces in the vector exist something like this: (+1,+2)(-1,+2)(+1,-2)(-1,-2)(+2,+1)(+2,-1)(-2,+1)(-2,-1) where the first number is the x and the second number is the y, and it check those numbers to see if it exists in the vector and if it exists and the piece hasn't been there yet it would return that it could move there and then move there. I'm not quite sure how to actually write that as a function and when it comes to the recursive function i'm completely lost.
#include "knight.h" //header file containing the Grid class
usingnamespace std;
bool voyagingKnight(Grid chessboard,int i,int j,int step);
int main()
{
int INITIAL = 0;
int rows = INITIAL , columns = INITIAL , count = 0;
vector<vector<int> > vec(INITIAL , vector<int>(INITIAL) );
Grid board; //Grid class I created to make the board
int IniRow=0,IniColumn=0;
cout<< "How many rows would you like?: ";
cin >> rows;
cout << "How many columns would you like?: ";
cin >> columns;
cout << "What row would you like to start in?: ";
cin >> IniRow;
cout << "What column would you like to start in?: ";
cin >> IniColumn;
board.setGrid(vec,rows,columns);//makes board
for(int i =0; i < rows; i++) //this displays the vectors in a grid
{
for(int j=0; j < columns; j++)
{
board.display(i,j);
}
cout << endl;
}
system("pause");
return 0;
}
bool voyagingKnight(Grid chessboard,int i,int j,int step)
{
//this is the recursive function that is supposed to solve this
}