KNIGHT’S TOUR
By Sasank P
P V Sasank
13CS01007
Under the guidance of
Dr P L Bera
WHAT IS A KNIGHT’S TOUR PROBLEM?
 A knight’s tour problem is a mathematical problem involving a knight
on a chess board . The knight on the chess board is moved according
to the rules of chess.
 A knight's tour is a sequence of moves of a knight on a chessboard
such that the knight visits every square only once.
A KNIGHT’S TOUR LEGAL MOVES
PICTORIAL REPRESENTATION
 Knight’s tour can be represented as a graph.
 The vertices -Represent the squares of the board.
 The edges -Represent a knight’s legal moves between squares.
KNIGHT’S GRAPH
TYPES OF KNIGHT’S TOUR PROBLEMS
There are two types of problems:
1. Closed
2. Open
Knight’s tour
• Closed
• Open
If knight ends on a
square from which
the starting square
can be reached by
the knight , Then
that tour is a
closed one.
If the beginning
square cannot be
reached , Then
that tour is open.
OPEN KNIGHT’S TOUR PROBLEM
CLOSED KNIGHTS TOUR
VARIOUS ALGORITHMS
 Brute force search
 Divide and Conquer
 Warnsdorff’s rule
BRUTE FORCE SEARCH
 Very general problem solving technique.
 Iterates through all possible move sequences.
 For a regular 8x8 chess board, there are approximately
4×1051possible move sequences.
DIVIDE AND CONQUER
 Divide the board into smaller pieces.
 Construct tours on each piece.
 Patch all the pieces together.
WARNSDORFF’S ALGORITHM
 Introduced by H. C. Warnsdorff in 1823.
 Can be solved in linear time.
 Very efficient algorithm for solving knight’s tour.
WARNSDORFF’S ALGORITHM
 Some definitions:
 A position Q is accessible from a position P if P can move to Q by a single knight's
move, and Q has not yet been visited.
 The accessibility of a position P is the number of positions accessible from P.
 Algorithm:
1. set P to be a random initial position on the board
2. mark the board at P with the move number "1"
3. for each move number from 2 to the number of squares on the board:
I. let S be the set of positions accessible from the input position
II. set P to be the position in S with minimum accessibility
III. mark the board at P with the current move number
4.return the marked board :each square will be marked with the move number on
which it is visited.
WARNDROFF’S RULE PICTORIALLY:
SOLVING KNIGHT’S TOUR
 2-D array of 8x8 is created to represent a chessboard.
 Each element in the array is assumed to be a square on the board.
 Initially all the elements are assigned to 0 , to indicate that knight has
not visited any of these squares.
 Shift the knight from the initial input position to anyone of the possible
positions and assign the number of that move to element in that
position.
 If we could not find a tour , then shift the knight to any other of the
possible solutions. In this way check all the positions till you find a
solution.
C PROGRAM FOR SOLVING KNIGHT’S TOUR
 ..DownloadsstudiesSeminarknights mainnew.docx
OUTPUT:
SOLVING KNIGHT’S TOUR USING WARNSDROFF’S RULE
 ..DownloadsstudiesSeminarknights wandmainnew.docx
OUTPUT:
INTERESTING FACTS ON KNIGHT’S TOUR
 26,534,728,821,064 closed directed knight's tours are possible on 8x8
board.
 The exact number of open knight’s tours is not found yet.
 It’s estimated to be about 1015 to (2*1016).
MAGIC KNIGHT’S TOUR
 The squares of the chess board are numbered in the order of the
knight’s moves.
 Full magic knight’s tour:
Each column, row, and diagonal must sum to the same number.
 Magic knight’s tour:
Each column and row must sum to the same number.
 Existence of full magic knight’s tour on 8x8 was a 150-year-old
unsolved problem.
 In August 5, 2003, after nearly 62 computation-days, a search
showed that no 8x8 fully magic knight’s tour is possible
KNIGHT’S TOURS AND CRYPTOGRAPHY
 A cryptotour is a puzzle in which the 64 words or syllables of a verse
are printed on the squares of a chessboard and are to be read in the
sequence of a knight’s tour.
 Knight’s tour is simply an instance of Hamiltonian path.
 A closed tour is a Hamiltonian cycle.
 Knight's tour problem can be solved in linear time.
CONCLUSION
 Warnsdroff’s rule is the best and efficient method to solve a knight’s
tour.
 Warnsdroff’s rule gives always a closed tour.
 Proficient usage of Data structures and the user interface help us to
code and understand the tour easily.
OUTPUT:
GRAPHICAL DISPLAY
THANK YOU
Q&A

Knights tour

  • 1.
    KNIGHT’S TOUR By SasankP P V Sasank 13CS01007 Under the guidance of Dr P L Bera
  • 2.
    WHAT IS AKNIGHT’S TOUR PROBLEM?  A knight’s tour problem is a mathematical problem involving a knight on a chess board . The knight on the chess board is moved according to the rules of chess.  A knight's tour is a sequence of moves of a knight on a chessboard such that the knight visits every square only once.
  • 3.
    A KNIGHT’S TOURLEGAL MOVES
  • 4.
  • 5.
     Knight’s tourcan be represented as a graph.  The vertices -Represent the squares of the board.  The edges -Represent a knight’s legal moves between squares.
  • 6.
  • 7.
    TYPES OF KNIGHT’STOUR PROBLEMS There are two types of problems: 1. Closed 2. Open
  • 8.
    Knight’s tour • Closed •Open If knight ends on a square from which the starting square can be reached by the knight , Then that tour is a closed one. If the beginning square cannot be reached , Then that tour is open.
  • 9.
  • 10.
  • 11.
    VARIOUS ALGORITHMS  Bruteforce search  Divide and Conquer  Warnsdorff’s rule
  • 12.
    BRUTE FORCE SEARCH Very general problem solving technique.  Iterates through all possible move sequences.  For a regular 8x8 chess board, there are approximately 4×1051possible move sequences.
  • 14.
    DIVIDE AND CONQUER Divide the board into smaller pieces.  Construct tours on each piece.  Patch all the pieces together.
  • 15.
    WARNSDORFF’S ALGORITHM  Introducedby H. C. Warnsdorff in 1823.  Can be solved in linear time.  Very efficient algorithm for solving knight’s tour.
  • 16.
    WARNSDORFF’S ALGORITHM  Somedefinitions:  A position Q is accessible from a position P if P can move to Q by a single knight's move, and Q has not yet been visited.  The accessibility of a position P is the number of positions accessible from P.  Algorithm: 1. set P to be a random initial position on the board 2. mark the board at P with the move number "1" 3. for each move number from 2 to the number of squares on the board: I. let S be the set of positions accessible from the input position II. set P to be the position in S with minimum accessibility III. mark the board at P with the current move number 4.return the marked board :each square will be marked with the move number on which it is visited.
  • 17.
  • 18.
    SOLVING KNIGHT’S TOUR 2-D array of 8x8 is created to represent a chessboard.  Each element in the array is assumed to be a square on the board.  Initially all the elements are assigned to 0 , to indicate that knight has not visited any of these squares.  Shift the knight from the initial input position to anyone of the possible positions and assign the number of that move to element in that position.  If we could not find a tour , then shift the knight to any other of the possible solutions. In this way check all the positions till you find a solution.
  • 19.
    C PROGRAM FORSOLVING KNIGHT’S TOUR  ..DownloadsstudiesSeminarknights mainnew.docx
  • 20.
  • 21.
    SOLVING KNIGHT’S TOURUSING WARNSDROFF’S RULE  ..DownloadsstudiesSeminarknights wandmainnew.docx
  • 22.
  • 23.
    INTERESTING FACTS ONKNIGHT’S TOUR  26,534,728,821,064 closed directed knight's tours are possible on 8x8 board.  The exact number of open knight’s tours is not found yet.  It’s estimated to be about 1015 to (2*1016).
  • 24.
    MAGIC KNIGHT’S TOUR The squares of the chess board are numbered in the order of the knight’s moves.  Full magic knight’s tour: Each column, row, and diagonal must sum to the same number.  Magic knight’s tour: Each column and row must sum to the same number.
  • 26.
     Existence offull magic knight’s tour on 8x8 was a 150-year-old unsolved problem.  In August 5, 2003, after nearly 62 computation-days, a search showed that no 8x8 fully magic knight’s tour is possible
  • 27.
    KNIGHT’S TOURS ANDCRYPTOGRAPHY  A cryptotour is a puzzle in which the 64 words or syllables of a verse are printed on the squares of a chessboard and are to be read in the sequence of a knight’s tour.
  • 28.
     Knight’s touris simply an instance of Hamiltonian path.  A closed tour is a Hamiltonian cycle.  Knight's tour problem can be solved in linear time.
  • 29.
    CONCLUSION  Warnsdroff’s ruleis the best and efficient method to solve a knight’s tour.  Warnsdroff’s rule gives always a closed tour.  Proficient usage of Data structures and the user interface help us to code and understand the tour easily.
  • 30.
  • 31.
  • 33.