Skip to content
Advertisement

Python Recursive Knight Tour

I’m trying to solve the knight tour algorithms with recursive backtracking method in python.

The solution should be a matrix with 24 documented steps, but it only count up-to 5 steps. It doesn’t enter the recursive if statement.

JavaScript

Advertisement

Answer

The problem I see is that you set yNeu = x + pos[1] when you probably meant yNeu = y + pos[1].

Another potential problem is that since you use 0 both for the first step and to mark unvisited squares, you can revisit the starting square later, so consider using -1 or None to mark unvisited locations.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement