Knight’s tour algorithm
-
Upload
hassan-tariq -
Category
Education
-
view
8.217 -
download
0
Transcript of Knight’s tour algorithm
![Page 1: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/1.jpg)
KNIGHT’S TOURExplanation and
Algorithms
![Page 2: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/2.jpg)
GROUP MEMBERS
Hassan Tariq (2008-EE-180)
Zair Hussain Wani (2008-EE-178)
![Page 3: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/3.jpg)
Introduction
![Page 4: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/4.jpg)
What is ‘Knight’s Tour’?
Chess problem involving a knight
Start on a random square
Visit each square exactly ONCE according to rules
Tour called closed, if ending square is same as the starting
![Page 5: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/5.jpg)
Constraints
A closed knight’s tour is always possible on an
m x n chessboard, unless:
m and n are both odd, but not 1
m is either 1, 2 or 4
m = 3, and n is either 4, 6 or 8
![Page 6: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/6.jpg)
m and n are both odd, but not 1
![Page 7: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/7.jpg)
Knight moves either from black square to white, or vice versa
In closed tour knight visits even squares
If m and n are odd i.e. 3x3, total squares are odd so tour doesn`t exist
![Page 8: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/8.jpg)
m = 1, 2, or 4; m and n are not both 1
![Page 9: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/9.jpg)
for m = 1 or 2, knight will not be able to reach every square
for m = 4, the alternate pattern of white and black square is not followed so tour not closed
![Page 10: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/10.jpg)
m = 3; n = 4, 6, or 8
![Page 11: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/11.jpg)
Have to be verified for each case
For n > 8, existence of closed tours can be proved by induction
![Page 12: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/12.jpg)
Algorithms
Neural Network Solutions
Warnsdorff’s Algorithm
![Page 13: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/13.jpg)
Neural Network Solutions
Every move represented by neuron
Each neuron initialized to be active or inactive
( 1 or 0 )
Each neuron having state function initialized to 0
![Page 14: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/14.jpg)
Neural Network Solutions (contd.)
Ut+1 (Ni,j) = Ut(Ni,j) +2 – Vt(N)
NG(Ni,j)
1 Ut+1(Ni,j) > 3 Vt+1(Ni,j) = 0 Ut+1(Ni,j) < 0
Vt(Ni,j) otherwise
![Page 15: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/15.jpg)
Neural Network Solutions (contd.)
The network ALWAYS converge
Solution: Closed knight’s tour Series of two or more open tours
![Page 16: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/16.jpg)
Warnsdorff's Algorithm
Heuristic Method Each move made
to the square from which no. of subsequent moves is least
![Page 17: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/17.jpg)
Warnsdorff's Algorithm (contd.)
Set P to be a random initial position on the board
Mark the board at P with the move number "1" For each move number from 2 to the number of
squares on the board: Let S be the set of positions accessible from the input
position Set P to be the position in S with minimum
accessibility Mark the board at P with the current move number
Return the marked board – each square will be marked with the move number on which it is visited.
![Page 18: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/18.jpg)
Comparison
NEURAL NETWORKS WARNSDORFF'S ALGORITHM
Complex algorithm (a lot of variables to be monitored)
Longer run-time NOT always gives a
complete tour
Simple algorithm Linear run-time Always gives a
CLOSED tour
![Page 19: Knight’s tour algorithm](https://reader035.fdocuments.net/reader035/viewer/2022062513/5570d489d8b42a1d358b56fb/html5/thumbnails/19.jpg)
Conclusion
WARNSDORFF’S ALGORITHM IS BETTER