|
C M S C 2 1 4 C o m p u t e r S c i e n c e I I S p r i n g 2 0 0 4 |
It is now. I removed the extra line before the output and there is
a space after the last -> (just like in the primary.output).
Yes, you need to throw an exception. This can be a
different exception than the one that detects an empty string.
In YOUR exceptions that you add to Except.cpp, use
"cerr" instead of "cout". In mine, I want the "cout" because
if you haven't changed them then if these exceptions are
thrown, your output will diff with mine. On the exceptions you
write, I have no way of knowing what you have printed.
I would. Changing the rows or columns does not automatically
resize the matrix because the constructor for board is setting up
the matrix dimensions.
Only the 1st instance. Let's say that there are 2
instances of ["W",1] in the list. If the Robot is on cell [0,2]
and moves ["W",1], she will now be at cell [0,1]. Then she can
move ["W",1] again (landing on [0,0]) if she wants to.
Sorry. I had the symbols in there but in html these are
tag designators so I had to use something else to represent these symbols.
Yes! You need to change the private data members "rows"
and "cols" in the Board class.
Yes. In Board.h and Mpair.h. I have put them in there.
This means that AFTER the 2nd private and the comment
Iterators can not walk off a circular list so don't throw an
exception.
Yes! Two or more moves of the same direction and units is
possible because if the robot is going to be moving, ["N",2] will
indicate a different cell depending upon where the Robot is
located at that time.
Since board has defaults for size of 6X6, we need a way to
reset the size and then read the data. The first line of
"board.dat" contains the board size for this particular
game. The remaining lines contain values to be stored in each row
of the board. So Row 0 has a 0 in the 1st cell, a 1 in the 2nd
cell and a 3 in the 3rd cell.
The matrix is a vector of vectors where the first argument
is the number of rows and the 2nd argument is a vector of columns
and initial values.
You are supposed to get the code from the text book. I
listed the page in the project description. The constructor and
index operator are in the text on page 266. If you don't have a
text, you can ask any TA to look at their text or come to my
office.
As there are no office hours this weekend and I am
finding compassion in my heart for those of you who are starting
this late without a text book, I have put the code up from the
text (actually from my program) that defines the constructor and
[ ] operator of Board.h.
abbreviate() is called in converter() and it doesn't
matter is you strip out the blanks first or they are left in. As long as
the blanks are gone when you call buildList().
Since you call stripper() in printDirVector(), you
should also call it from converter() so that is
printDirVector()is not called, the blanks will still be gone.
converter() must be called in main() but
printDirVector() and printPairsVector() will not necessarily
be called in main.cpp on other tests we run.
I have put 2 other files up: but for submitting, you MUST use main.cpp; do not tar up the
another.main.* files.
Notice in the Board constructor, the board defaults to 6X6. But
when you read the file "board.dat", the first line indicates the size of
the board for this particular game, which is 3X3. You need to resize the
board and fill it with the default value for it's cells, the integer 0 in
this case. So T means 0, zero, in project 1.
Since we will eventually templatize the Board, we could change the
contents later to hold characters instead of integers. So leave the T in
the comment and realize that it should have said 0.
I decided to wait on the Robot class until project 2. So
just leave this in your header file but do not put it in your
Board.cpp. You can't implement this until you have a Robot.
When you read "moves.dat", store the strings in the vector
"dir". Since input/output is the slowest part of your program, we
want to just read the strings, as they appear in the file, and
then store them, unprocessed.
converter() then takes this vector of unprocessed
strings
and turns them into a vector of "pairs" where "north west" will
be converted to "NW" and the string "2" will be converted into
the integer 2. So in "moves.dat" the line "north west 2" would be
read by reader(), stripped of spaces by stripper()
and then converted
to the Pair ["NW",3] and stored in vector "pairs".
buildList() takes each element in the "pairs"
vector and
inserts each pair into the circular doubly linked list by
repeatedly calling insert() for each Node that is created.
insert() creates the Node and fills it with a Pair such as
["NW",3]
I've changed the comment in operator>
No! the units in Pair will never exceed 9 (because the
largest board you will probably have will be 6X6.) For that
matter, the board values will never be larger than 9 either.
Eventually the Robot will be placed on the board and she will be
represented by the single digit 9, while the Stalker will be the
single digit 8.
The "direction" part can be one of 8 strings, whose order is the
same as alphabetical order If the two directions are not the same, you already know which is
smaller and which is larger as determined by the string. If both
directions are the same, then you compare the "units" to determine which
is smaller.
You must use the main.cpp provided except that you may
add other catch clauses after the 2 exceptions I placed there
and before the ellipsis.
Notice that there is no primary.input because
you are reading files in both reader() methods.
Project #1 is due by 11pm on Friday, February 20th, 2004.
// YOU MAY PUT ANY PRIVATE METHODS
HERE
you do not have to implement my functions. I meant to remove
getValue() from Board.h but overlooked it. Just leave it in
there and you need not implement it.
another.main.cpp
and
another.main.output
E < N < NE < NW < S < SE < SW < W
|
See the class syllabus for policies concerning email First Modified: Feb 5, 2004 |
|
|
|
|
|