Below is the code I am using to test backtracking algo to solve knight's tour, and it's not able to solve for odd board sizes. I would really appreciate if someone could point out the error in the code.
The code works fine for boards of even size, but it fails to find a solution for boards of odd sizes.
def get_valid_moves_warnsdorff(moves, x, y, size):
valid_moves = [(valid_move, len(get_valid_moves(moves, x + valid_move[0], y + valid_move[1], size))) for valid_move in get_valid_moves(moves, x, y, size)]
sorted_moves = sorted(valid_moves, key=lambda w: w[1], reverse=False)
return [move[0] for move in sorted_moves]