| CS 311 Fall 2009 > Assignment 4 |
Assignment 4 is due at 5 p.m. Tuesday, October 13. It is worth 25 points.
This assignment is to be done individually.
E-mail
answers to the exercises below to
ffggc@uaf.edu,
using the subject
“DA4”.
counthsw.h and counthsw.cpp, from Exercise A.
The two files (or a single archive file containing them)
should be attached to your e-mail message.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. Mark one square as forbidden, another square as start and yet another square as end. We will call the result a board.
We consider a spider that is placed on the start square. The spider can walk to an adjacent square: north, south, east, west, or any of the four diagonal directions. It does this repeatedly until it reaches the finish square. A way of doing this that does not touch the forbidden square, and touches each other square exactly once, is called a holey spider walk (HSW).
For more information on boards and HSWs, along with illustrations, see slides 9–12 from the Monday, October 5 lecture slides.
Write a C++ package that counts the number of holey spider walks on a given board. Be sure to follow the coding standards. Standard 3A (“Requirements on template parameter types must be documented.”) and standard 3B (“If a function is not a template and not a member of a class template, then the exceptions it throws must be documented.”) now apply. You do not need to follow standards 3C or 3D.
Here are the details for function countHSW.
int countHSW(int size_x, int size_y,
int forbid_x, int forbid_y,
int start_x, int start_y,
int finish_x, int finish_y);
Coordinates for the forbidden, start, and finish squares
range from 0 to size–1
in both the x and y directions.
Thus we must have 0 <= forbid_x < size_x,
and similarly for the y-coordinate and the other values.Notes:
I have written a test program: counthsw_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 counthsw_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 Fall 2009: Assignment 4 / Updated: 8 Oct 2009 / Glenn G. Chappell / ffggc@uaf.edu |
|