Professional Documents
Culture Documents
2022-CSC14003-20CLC-Lab01-đã chuyển đổi
2022-CSC14003-20CLC-Lab01-đã chuyển đổi
2022-CSC14003-20CLC-Lab01-đã chuyển đổi
The existence of solutions: It is proved that for any m n board with m ≤ n, a closed knight's tour
is always possible unless one or more of these three conditions are met:
- m and n are both odd
- m = 1, 2, or 4
- m = 3 and n = 4, 6, or 8.
It is also proved that on any rectangular board whose smaller dimension is at least 5, there is a
(possibly open) knight's tour.
Implementation requirements
You are asked to implement the following strategies to find any knight's tour (either closed or
open) starting at square (x, y) available on a rectangular board of size m × m . The parameters, x, y
and m, are user-specified positive integers (m ≥ 5 and 1 ≤ x, y ≤ m).
The following example shows a knight’s tour starting at (x, y) = (5, 1) on a board of size 8 × 8.
59 14 63 32 1 16 19 34
62 31 60 15 56 33 2 17
13 58 55 64 49 18 35 20
30 61 42 57 54 51 40 3
43 12 53 50 41 48 21 36
26 29 44 47 52 39 4 7
11 46 27 24 9 6 37 22
28 25 10 45 38 23 8 5
1
A. Backtracking [2]
This strategy addresses the problem in an incremental way. We initially start from an empty
solution vector and one by one add items (that is, each item is a Knight’s move). When adding an
item, we check if the current solution violates the problem constraint, if it does then we remove the
item and try other alternatives. If none of the alternatives works out, we go to the previous stage
and remove the item added in the previous stage. No solution exists if the initial stage is reached
during the backtracking (note that, it is different from reaching the initial stage in the last step for a
closed tour). If adding an item does not violate constraints, we recursively add items one by one.
We stop the search and print the solution when the solution vector becomes complete.
Report requirements
We consider two strategies, backtracking and Warnsdorff’s Heuristic, and three different board
sizes (including 8, 15 and 25).
For each strategy and for each board size, run the knight’s tour with five different initial positions.
Report the average number of moves and the average running time in each case to both a table and
a chart.
Problem representation
Input: The parameters, x, y and m, are obtained from the command line of the following format
executable filename -px x -py y -s m
where executable filename is the name of the executable file, which is exactly your Student ID,
and the knight starts at square (x, y) on the board of size m. -px, -py and -s are predefined
indicators of corresponding parameters. For example, 1853001.py -px 5 -py 1 -s 8
The input values are assumed to be valid. You do not have to check them.
2
Output: The result is written to a the text file studentID_strategy.txt, where
studentID is your Student ID and strategy is either backtrack (for the backtracking
strategy) or heuristic (for the Warnsdorff’s Heuristic). The format of the file is as follows.
The first line lists the three values, x, y and m, which are separated by white spaces.
The second line shows the number of moves made by the specified strategy (backtrack
moves are not included if using backtracking)
The third line shows the actual running time measured in milliseconds.
The next lines present the result as a square matrix of size m × m. Each line shows a row in
the matrix, in which values are separated by white spaces. Any square can be either -1
(unvisited) or some value in the range [1, m2] (visited, the step in the tour).
References
[1] https://en.wikipedia.org/wiki/Knight%27s_tour
[2] https://www.geeksforgeeks.org/the-knights-tour-problem-backtracking-1/
[3] https://www.geeksforgeeks.org/warnsdorffs-algorithm-knights-tour-problem/
Rubric
Your results will be checked automatically by a program, and thus please be sure that your
input and output data format conform the lab requirements.
Any work that commits one or more of the following issues is considered totally unqualified
and hence gets 0% credit.
- Any plagiarism: Refer other student’s work or any other sources of materials without
citation, or copy them. The lab assistants decide the threshold of similarity.
- Uncompilable (syntax errors) or unable to produce the output (run-time errors)
- The input and output do not follow the specifications.
# Criteria % credits
1 Manipulate the input and output 10
2 Implement the backtracking 10
3 Implement the Warnsdorff’s Heuristic 10
4 Provide valid results for the backtracking strategy 20
5 Provide valid results for the Warnsdorff’s Heuristic 20
6 Provide all evidential files in the OUTPUT folder 10
7 Report sufficient information in the document 20
(This will be ignored if your work does not meet Criteria 6)
Submission preparation
This is an INDIVIDUAL assignment.
Prepare a folder that includes the following subfolders
- SOURCE: all Python (or C/C++) files should be put in here
- OUTPUT: all evidential files necessary for the report
- DOCUMENT: a PDF-formatted file that presents a check list of what you have/have not done,
and a statistical report described above.
Name the main folder following your Student ID and compress it in common format.