backtracking.knight_tour ======================== .. py:module:: backtracking.knight_tour Functions --------- .. autoapisummary:: backtracking.knight_tour.get_valid_pos backtracking.knight_tour.is_complete backtracking.knight_tour.open_knight_tour backtracking.knight_tour.open_knight_tour_helper Module Contents --------------- .. py:function:: get_valid_pos(position: tuple[int, int], n: int) -> list[tuple[int, int]] Find all the valid positions a knight can move to from the current position. >>> get_valid_pos((1, 3), 4) [(2, 1), (0, 1), (3, 2)] .. py:function:: is_complete(board: list[list[int]]) -> bool Check if the board (matrix) has been completely filled with non-zero values. >>> is_complete([[1]]) True >>> is_complete([[1, 2], [3, 0]]) False .. py:function:: open_knight_tour(n: int) -> list[list[int]] Find the solution for the knight tour problem for a board of size n. Raises ValueError if the tour cannot be performed for the given size. >>> open_knight_tour(1) [[1]] >>> open_knight_tour(2) Traceback (most recent call last): ... ValueError: Open Knight Tour cannot be performed on a board of size 2 .. py:function:: open_knight_tour_helper(board: list[list[int]], pos: tuple[int, int], curr: int) -> bool Helper function to solve knight tour problem.