/knights_path

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Algorithm for shortest path of Knight

Depth search

Depth search of chessboard is stored in depth_first_search package, knights_tour file and for user interaction console file

Knights Tour

Knight tour contains class KnightTour that stores implementation of depth first search algorithm and Warnsdorff's rule

KnightTour class contains:

  • Constructor Method that initialize class, get chessboard size from user input, chessboard that generate chessboard that is list of lists which is representation of squared chessboard of chessboard size and it's filled with -1, moves row that represent how knight can move on the chessboard, moves row represents the possible changes in the row positions, moves column represents the possible changes in the column positions, count represents the number of possible moves. Returns None

  • Find path Method that starts the search for a knight's tour from the given position, Row index to start the tour from, default is 0. Column index to start the tour from, defaults to 0.

  • Is valid move Private method that checks if the given position row column is a valid move. Row index of the move , Column index of the move. Returns True if the move is valid, False otherwise.

  • Warnsdorffs count Private method that counts the number of possible moves from the given position using the Warnsdorff's heuristic. Row index of the move, column index of the move. Returns count of possible moves

  • Depth first search Private method that uses Depth-First Search to find a knight's tour from the given position. Row index to start the search from, Column index to start the search from, move count is move number in the tour of knight.

  • Print Path Private method that prints the found knight's tour.