19
KNIGHT’S TOUR Explanation and Algorithms

Knight’s tour algorithm

Embed Size (px)

Citation preview

Page 1: Knight’s tour algorithm

KNIGHT’S TOURExplanation and

Algorithms

Page 2: Knight’s tour algorithm

GROUP MEMBERS

Hassan Tariq (2008-EE-180)

Zair Hussain Wani (2008-EE-178)

Page 3: Knight’s tour algorithm

Introduction

Page 4: Knight’s tour algorithm

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

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

m and n are both odd, but not 1

Page 7: Knight’s tour algorithm

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

m = 1, 2, or 4; m and n are not both 1

Page 9: Knight’s tour algorithm

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

m = 3; n = 4, 6, or 8

Page 11: Knight’s tour algorithm

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

Algorithms

Neural Network Solutions

Warnsdorff’s Algorithm

Page 13: Knight’s tour algorithm

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

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

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

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

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

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

Conclusion

WARNSDORFF’S ALGORITHM IS BETTER