Your recursive method has no base cases. Even if they did, your entire program is written in tail recursion, so whenever you return to a previous point in the stack, you don't have any control there because the only time you make the recursive call is in a return statement.
Here's how I would approach the knight's tour (in pseudocode):
/* Path is a list of coordinates that represent the tour so far. */
global list path = new list
boolean ktour( move ):
path.append(move)
if ( sizeof(path) == 64 /*tour is complete*/ ):
return True
for each move M that can be made:
if ( ktour(M) ):
return True
path.remove(move)
return False
/* Begin the program. */
ktour( (0,0) )
See how I never do a return(ktour(M)) ? I use the value of the method to take control of the program again whenever the method fails.
Good luck, and I hope this helps out.
IsharaComix
Junior Poster in Training
98 posts since Feb 2010
Reputation Points: 109
Solved Threads: 23
Skill Endorsements: 0
When you backtrack, you don't set grid[row][col] back to zero like you should.
Other than that, the program looks just fine. Of course, a brute-force implementation of the Knight's tour would probably take forever to run, so you may not get any meaningful results after executing the program. But it should give you a correct answer... eventually.
IsharaComix
Junior Poster in Training
98 posts since Feb 2010
Reputation Points: 109
Solved Threads: 23
Skill Endorsements: 0
You'll be more likely to get useful help if you start a new thread, this one is six months old and your post has nothing to do with the knight's tour problem.
You'll be even more likely to get useful help if you put in some effort instead of just asking people to do your homework for you. Why don't you try to solve the problem, and then ask questions about the places where you get stuck?
jon.kiparsky
Posting Virtuoso
1,849 posts since Jun 2010
Reputation Points: 383
Solved Threads: 187
Skill Endorsements: 3