|
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 |
I envisioned play() doing the following:
Leave it in the code but don't implement it.
Sorry! You should change it back to the way it was in project 1.
No! This is not contradictory. The Board still has
positive values and the Robot still has valid moves. So the Robot
keeps moving, even if it is to a cell with 0 points, in order to
reach a cell with + points on a subsequent move or moves.
Let's assume that the robot will have enough valid moves in
the cdll to get (eventually) to the cell with points. This will
only work IF you are always choosing the first move in the list
that results in the same number of points AND you are always
choosing the reachable move with the maximum number of points.
(Sometimes the max points will be 0.)
So if E2, NW1 and S3 are in the list and are valid reachable
moves, but all have a value of 0, the Robot MUST choose E2, the
first one in the vector of valid, reachable moves.
The Board constructor is exactly the same one I gave
everyone in the FAQ in project 1. You initialize the board to
zeroes in this case. "board.dat" is called from the reader(). I
changed the comments in Board.h. Get the
newest version of Board.h
Since the Stalker captures the Robot, only 8 appears on the
board.
I can tell you how and where I used it, but your code may be
different. prev stores the contents of a cell the Stalker is
about to land on because if the points are negative, they must be
restored when the Stalker leaves that cell. In refresh(), I saved the
contents of the cell and then put the Stalker on that cell. In play(),
I reset the cell after the Stalker moves. I also saved the contents of
the cell Stalker was about to be placed on in initialize().
Yes, you can use Dit for this project but not for project 3.
The Stalker, like the Robot, can initially start the game by
being placed on a cell with points.
If you don't get a pre-graded version of project 1 sometime this
weekend, you can still figure out what we tested that failed in P1. Just
run the tests in the posting directory for project 1, which were posted on
February 26.
Yes! Clearly, your code on project 2 cannot be tested with
"moves.dat" being empty because the cxx compiler does not allow one to
save a file with nothing in there. So the best I can do is read a file
that does not exist. But then we all would get a seg fault. Again, no
good. So don't worry about it this go-round.
NO! The Robot will get the points of the cell it lands on. If those
points are negative, she could begin the game with negative points.
The argument is superfluous but we will keep it in there for
project 2.
We need to determine if the Stalker made a move because we have
to (possibly) reset the value in the cell it used to occupy before the
move. So if true is returned, the Stalker successfully made a move.
Is the following code in your makefile?
Okay, I placed the old, incorrect primary.output in
old.primary.output in
the posting account. The new correct version is in primary.output. It is
correct as of 3:15PM on March 1, 2004. Sorry about all that. I told you to
always choose the 1st element in the cdll that gave you the most points
and then my code did not work correctly due to my failing to initialize
correctly - it didn't work if the first good move was at the front of the
list. Now all is well (we hope).
Yes.
By the way, any code AFTER the line:
It turns out that inRange() in both Stalker.h and Board.h
are extraneous - unnecessary. I removed both. They were leftovers
from a previous implementation. Please update
your Stalker.h and Board.h
Yes there are. When the Robot is on [1,0] it can move
N1 or W1. Both moves are legal. This tells you that in
getBestMove() in the Board class, the best move (let's call
this BEST - it has some value, X) is only changed if
the new move is greater than X (not greater than or
equal to X). Since N1 has 0 and W1 has 0 and N1 is located
BEFORE W1 in the cdll, BEST will be set to N1 first and
since W1 results in the same number of points, W1 does not
replace N1.
Perhaps I should begin with Board's play(). In play,
we do the following: Now for Robot's makeMove()
Now that I look at my code, the parameter Node * in
makeMove() is not necessary - it should have been a local
variable. This is left over from an older version of this
project. We are going to leave it in there. But "ptr" gets
initialized in findMove()
Not really. It is in Stalker.h which is included so Board.h will
get that file included when it is compiled.
The most nodes you print on a single line is 7 nodes (and 7
arrows) before doing a carriage return. A line is "full" at 7 nodes.
If either the Stalker lands on the Robot or the Robot lands on the
Stalker, the game is over and the Robots points are zero.
(Blush!) I assumed that my output was perfect so I did not check
all the way to the bottom. When the Robot is at [1,0] (after earning 9
points), she moves ["N",1] to [0,0] but there was no ["N",1]. The output
shows the move ["N",1] and then E2 was deleted from the linked list. I
have changed the files "moves.dat" and "primary.output". I believe this
is now correct.
The reason we no longer use the g++ compiler for your projects is
due to the strange way templatized classes must be handled there. If you
have a Foo class
(with a Foo.h and a Foo.cpp) and Foo is templatized, you need to do the
following in Foo.h ONLY FOR THE g++ COMPILER: When you go to submit your project, the cxx compiler works as was
demonstrated in class, so you should use the format in temparr1.cpp and
temparr2.cpp in the posting account in Handouts/
In the operator== in Pair.h, the const belongs outside of the ()
instead of inside. It has been corrected in the posting account.
After you have determined which move is the best one (it is the one
that is within range of the robot and has the highest points) it will be
an Mpair. You change the robot's position (and change the number of points
the Robot has, if the cell the Robot moves to has contents != 0).
inRange() is determining of the moves in the cdll, which ones are
currently reachable from the Robot's current position.
The comments on this function were meant to be an example. I cannot
tell you what each direction means because it depends upon what is in the
Moves cdll and where the Robot is located. You need to write the function
that will be able to make the correct move irregardless of these caveats.
I suggest you take paper and pencil and draw the first move, figure
out which Moves in the cdll will work (that is the inRange() part) and
determine how to make a generic function that will do this. If you try
with 3 or 4 moves, it should dawn on you.
This is why there are many public functions in the 2 classes. You
need to pass information back and forth between the Robot and Board and
between the Stalker and Board. You store the Robot's position in Robot but
you move it in Board, so you have a couple of functions that help:
Robot::setPosition() and Board::setRobot().
According to Chris, it has to do with type nesting. So while you
can do this: The bolded version above is preferrable.
Yes they are. I am going to leave both in because my code may use
both and I don't want to change it at this point.
One of your TAs, Michael, who is implementing this
project, had
several suggestions that I incorporated into P2. Most involve
correcting or expanding upon comments. One was an added method
to Pair.h (the overloaded = =).
We feel that this will help your understanding and ease
your pain (of implementation.)
Please get the newest tar file or recopy the .h files
that have changed.
Your TA Chris has the following suggestions:
Remove all .o, cxx_repository/, tarballs, core, and
executables from all of the project directories. You should
LEAVE your .cpp, .h, test input/output files, and makefiles there
You should have enough space to keep all of your old
project header,
implementation, makefiles, and input/output files. The only
large amount of space will be core dumps and executables.
If you feel like you should clean out your directories, tar
and gzip your directory and ship it to another computer. If you are not debugging at all, or you do not use the
ladebug debugger, remove the -g flag. Also, if you are not using a
debugger, the core dump is useless. You can safely:
Only make executables you are testing.
Use subdirectories. The compiler can be tricked into
thinking it has more memory than it does if you work from a
subdirectory.
If none of the above works, you can do a temporary fix
but you must do this every time you log into your bt214
account. Type:
unlimit filesize
You have 10 meg of memory so I am not certain why some
of you are running out of memory. It should be able to get you
through all 6 projects.
I changed the comment in Moves.h on the default
constructor. It used to say "initializes front and rear". It
now says "initializes front".
Project #2 is due by 11pm on Monday, March 8th, 2004.
clean:
\rm
-rf cxx_repository
This will remove the cxx subdirectory and all its contents.
// ADD ANY PRIVATE MEMBER METHODS HERE
need NOT be coded. They are suggested methods. Any code BEFORE that line
MUST be implemented.
#ifndef FOO_CLASS
#define FOO_CLASS
template
class Foo {
...
};
#include "Foo.cpp"
#endif FOO_CLASS
vector<Pair>::iterator it =
pairs.begin();
and
typename vector<T>::iterator it =
pairs.begin();
your cannot do:
vector<T>::iterator it = pairs.begin();
tar -zvcf px.tar.gz px/ will tar and gzip the tar for
all files in px/ into px.tar
tar -zvxf px.tar.gz px/ will untar and gunzip all the
files from px.tar into a directory px
limit coredumpsize 0
Core dumps are usually large, and this will stop the executing
environment from creating a core dump.
|
See the class syllabus for policies concerning email Last Modified: Feb 19, 2004 |
|
|
|
|
|