This preview shows pages 1–2. Sign up to view the full content.
Programming Assignment #4
Submit file is due Tuesday, February 28, 2006 at 10:30 am
Hard copy is due at the beginning of class the same day
This assignment will exercise your skills in implementing a recursive algorithm. The task is to implement a solution to a classic
problem known as The Knight's Tour. The goal behind the problem is to place a knight on the a chess board and have it make
moves in such a way as to visit all of the squares exactly once. So, on a normal 8x8 chessboard, the knight will have to make at
least 64 moves to cover the entire board.
The completed tour using static (naive) searching required
27,241,113 moves.
The completed tour using heuristics (smart searching)
required 64 moves
Details
Instead of simply hardcoding the algorithm to manipulate an 8x8 board, we are going to extend the algorithm so that it can
handle boards of any size (square and nonsquare). There are many solutions (tours) that satisfy the criteria mentioned above,
and as it turns out, a recursive solution is the simplest to implement. Your solution to this exercise will involve a technique
called
backtracking
. (Backtracking is a popular technique that computers use to solve problems by systematically evaluating all
possible solutions and we've talked about backtracking in class.) The interface to the algorithm is simply a single call to a
method of the class
GameBoard
named
KnightsTour
, which is describe below.
bool
GameBoard::KnightsTour(
unsigned
row,
unsigned
column, TourPolicy policy = tpSTATIC);
Parameters and return value
Description
row, column
The row/column that the knight will start from.
policy
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '07
 Mead

Click to edit the document details