| CS 311 Spring 2008 > Assignment 4 |
Assignment 4 is due at 5 p.m. Tuesday, March 4. It is worth 20 points.
E-mail answers to the exercises below to ffggc@uaf.edu, using the subject “DA4”.
In this exercise, you will implement recursive search with backtracking.
This exercise does not emphasize implementation details and language features nearly as much as earlier programming exercises did. You still need to write high-quality code and follow the coding standards; however, this should be relatively easy, for those that did a decent job on the previous assignments.
The key part of this exercise is the logic that the code must follow. When you do this exercise, it is probably worthwhile to spend more time planning, and less time coding, than you have before.
Consider a rectangle divided into squares, like a checkerboard or chessboard. Call one square the “start” square and another square the “end” square. We will call the result a board.
A spider is placed on the start square. It steps to an adjacent square north, south, east, west, or in one of the four diagonal directions, then does this again, etc. We want the spider to visit every square on the board exactly once, never leave the board, and finish on the end square. We call the path it follows a spider tour.
For more information on boards and spider tours, along with illustrations, see the Monday, February 25 lecture slides [PDF], slides 9–12.
Write a C++ package that counts the number of spider tours on a given board. Be sure to follow the coding standards. Standard 3A (“Requirements on template parameter types must be documented.”) and standard 3B (“Exceptions thrown by each function must be documented.”) now apply. You do not need to follow standard 3C.
Here are the details for function countSpiderTours.
int countSpiderTours(int size_x, int size_y,
int start_x, int start_y,
int end_x, int end_y);
Coordinates range from 0 to size-1 in both the x and y directions.
Thus, for example, we must have 0 <= start_x < size_x,
and similarly for the end square and the y-coordinates.Notes:
I have written a test program: spidertours_test.cpp. If you compile and run your package with this program (unmodified!), then it will test whether your package works properly.
Do not turn in spidertours_test.cpp.
Notes:
This exercise emphasizes logic, not efficiency. For grading purposes, running in a reasonable time is all I ask; you will not be given extra credit for super-fast code.
However, for those who like a challenge, once you get your code working, see how fast you can get it to run. I will do timing tests on all working implementations; the names of top performers will be announced in class some time after the homework is graded.
| CS 311 Spring 2008: Assignment 4 / Updated: 26 Feb 2008 / Glenn G. Chappell / ffggc@uaf.edu |
|