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 2


Project #3

Due Date Friday, November 8th, by 11pm

Early Bonus Date Thursday, November 7th, by 11pm (+5 points)

Project #3 Checklist

Project 3 Checklist

Click above before submitting (LINK not ready).

Project #3 Updates

You are expected to read updates on a daily basis.

Updates

Project #3 FAQ

Some of your questions may be answered here. Read before sending email.

You are expected to read FAQ on a daily basis.

Project #3 FAQ

Your Responsibility

Read this webpage often. Read the FAQ often. Read README.updates in the posting account often.

Get started right away.

Purpose

  1. To write a BstSortedList template class, which implements a binary search tree with nodes which have pointers to left and right children as well as predecessors and successors. This class has the same functionality as SortedList but is implemented using BSTs.
  2. To write recursive functions. In particular, many of the BstSortedList methods will be recursive.
  3. To add some features to the Sokoban game.
  4. (EXTRA CREDIT) To write a BstMap class. You will be provided a Pair class and a PairComparator class. BstMap is similar to STL's implementation of its map class (it uses a BST of pair objects).
  5. To debug code from previous project, so that it doesn't give you problems on this one.

Academic Integrity Statement

Please note that *all* programming projects in this course (including this one) are to be done independently or with the assistance of the instructional staff of this course only.

Please review the policies outlined on the class syllabus concerning the use of class computer accounts and concerning the University's Code of Academic Integrity. The instructors of this course will review the programs submitted by students for potential violations of the Code of Academic Integrity and if it is believed that a violation has occurred it will be referred to the Office of Judicial Programs and the Student Honor Council.

Hardcoding is considered a violation of academic integrity

Background

In project 2, you implemented a SortedList interface using a doubly linked list. The interface consists of:

Interestingly, a binary search three also implements this same interface. From the class user's point of view, a SortedList implemented as a doubly linked list and a SortedList implemented as a binary search tree are the same. While, you, the implementer will notice the differences right away, the user of the class should not notice the difference in functionality.

The user of the class never has to know exactly how SortedList is implemented, unless they really are concerned about efficiency of the operations.

Good coding practice suggests that you "program to an interface". This is easier done in Java than in C++, but the idea is that an interface (which is a list of public methods defining an abstract data type (ADT)) allows many implementations, and you can simply substitute the appropriate implementation as needed without chaing the interface.

We won't quite do this in this project, but you should appreciate the idea of a binary search tree is implementing a SortedList interface, and that semantically, a user only needs to know it's a sorted list.

Background Reading

Please read the following as you do the project.

Files Provided

In addition to the primary input and primary output, the following files are in the posting account under Projects/P3.

Note: Implementing BstMap will be worth up to 5 points of the project. If you find yourself pressed for time, you may wish to skip the implementation of this class.

Files Submitted

Use Project 3 Checklist (above) as final check for project submission

Class Specifications

Tasks

The following is a suggested way to approach the project.

Task 1: Finish Project 2

Since the game has only small changes, you should get the commands to work, and finish that up.

Debug code as needed.

Task 2: Answer questions from TreeExercise.questions

Answers should be typed in TreeExercise.answers. The purpose of this is to help you understand BSTs before writing any code. This is often a good exercise. Once you understand the "theory", it should be easier to write the code.

Task 3: Finish up any code you didn't write, and documentation from Project 2.

If there's anything left you need to work on (comments, documentation, etc), please finish that. The documentation refers to classes with the "mine.h" extension.

Task 4: Add the following constructor to the ArrayList.

Write a constructor for ArrayList that takes a vector of the same type as the ArrayList and uses it to initialize the ArrayList.

Here are the specifications: ArrayList

Task 5: Except for Tokenizer, replace all STL vectors with ArrayList.

You can add new features to ArrayList, but only if comparable features exist in vector. The changes should make sense for vectors, and not be entirely specific to this project (i.e., don't assume you are carrying ArrayList of Item objects).

The purpose is to stress-test your ArrayList and to show your ArrayList is roughly comparable to a vector.

Task 6: Write MovieBstSortedList unit test

Name the file BstSortedListMovieUnit.cpp and BstSortedListMovieUnit.h. Initially, you will unit test a MovieBstSortedList, but then convert it to BstSortedList<Movie, MovieComparator> after you are done templatizing. The unit tests should remain identical, except for this change.

Come up with at least 5 tests (10 tests should be easy enough, given the number of methods).

Task 7: Implement MovieBstSortedList

Here is the MovieBstSortedList Specifications.

You will be provided a MovieBstSortedList.h file. You may wish to use a shorter name when writing this code, as you won't submit this However, it's easier to write and debug non-templatized code, which is why you're asked to implement a non-templatized class first.

(10/27) Add string getTitle() const method to Movie. Notice that Movie does not define operator<. DON'T define it. This will give a reason to use the MovieComparator class which will have to use getTitle() and do the comparison in MovieComparator (which it should do case-insensitively).

Implementing remove()

When implementing remove(), you should use one of the following techniques:

If you use left standard or right standard, you may either choose to copy the data of the replacement node (i.e., the predecessor or successor) and overwrite the node that's being removed, or actually remove and delete the node to be removed, and put the replacement node in its place. (This technique has been discussed in class and lab, and should be in the book).

Remember to handle pred and succ pointers.

Also, one variation when removing a node with one subtree is to always "pull" up the remaining subtree. Otherwise, if you are using, say, left predecessor, you can still use that technique provided there's a left subtree, and pull up the right subtree, if there's not.

In the README, you will describe which remove() method you used.

Task 8: Templatize MovieBstSortedList into BstSortedList and use BstSortedList<Item, ItemComparator> in place of SortedList<Item, ItemComparator>.

You will be given a partial BstSortedList.h and BstSortedList.cpp. The rest should be filled out by you using MovieBstSortedList as a guide.

To show that SortedList and BstSortedList implement the same interface, you will replace SortedList<Item, ItemComparator> by BstSortedList<Item, ItemComparator>.

Task 9: Add new features to the game.

Add features to the game as described below. They are mostly minor.

Task 10: Implement BstMap class. (Extra Credit: +5 points)

This is extra credit. Given a BstSortedList template class and a Pair class, create a BstMap class. This class behaves like the SimpleMap class, but is implemented using pairs and BSTs, which is similar to how map classes are implemented in STL.

Here is the BstMap Specifications.

Game Rules

These are additions/changes/reminders to the game.

These facts are from P2, but placed here for additional clarity.

  1. Food items may initially appear on target squares.
  2. When a box with food items on top moves, the food items move with the box.
  3. There will be at least one target square without a box on it.
  4. There will be at least one target square.
  5. A player is initially placed on an empty square or an empty target square.
  6. When listing a range of boxes for error messages, list the box closest to the player to the box furthest away.
  7. When listing boxes that are too heavy, list the fewest number of boxes that are too heavy (thus, if there are 6 boxes that the player is pushing, but the nearest 3 boxes are too heavy for the player, only list the range of the 3 boxes).
  8. Ranges should be listed even for a single box that is too heavy. In that case, the range is the same coordinate of the box in both cases.
  9. In commands from the input file, food items are written with double quotes. Box color are written using no quotes.

New changes to the game.

  1. The number of boxes no longer have to match the number of target squares. There may be more boxes than target squares or fewer boxes than target squares. There will be at least one target square, but zero or more boxes.
  2. If a player is on a target square, you should now print "&" (ampersand). If a player is not on a target square, print "=".

Commands

Case-insensitive

The commands, as usual, are case-insensitive. They may be any mix of upper and lowercase characters, but spelled correctly.

Furthermore, the box color or item name can also be in any case. You should print the output BNF for the box color and item name using the same case as in the command from the input file.

If a player wants to pickup a BAGEL, or bagel, or Bagel, from a "red" or "RED" or "ReD" box, this should work, provided there is a bagel on a red box adjacent to the player.

Older commands

All commands from P1 and P2 should work in P3, with modifications as stated. In particular, the P2 versions of DROP and PICKUP should work as well as the new version (the P2 version specifies individual items).

Requirements

Additional requirements

Makefile

Use macros like CC and CFLAGS. Make sure it generates .o files. Add the .cpp files to the dependencies list of classes that use the templates classes you wrote.

Also, make sure any class that USES a template class adds the .cpp file as a dependency. For example, if Foo.mine.cpp or Foo.mine.h uses a ArrayList<int>, list BOTH ArrayList.h and ArrayList.cpp as dependencies.

Debugging Hints

When you write the code, obviously, use the unit test driver. You need to submit it anyway, so use it. The more things you test, the better.

Also, for ArrayList, it's a good idea to print a message indicating you've gone out-of-bounds, if the index is out-of-bounds. Notice that regular arrays won't tell you such things.

Also, if your executable exceeds about 5 M, you should make sure that you run:

  unlimit filesize
which allows the files to be as large as your quota permits. This command has to be run each time you log in.

This prevents core dumps because of excessive file sizes.

If you use the -g option, the size of the executable will be much larger, so use this option only when you need to use the debugger.

Furthermore, for quota purposes, go to earlier projects and remove .o files, executables, etc. If you have space in your WAM account, you may wish to copy files of earlier projects there, to back them up (again, removing .o files). Remove core dumps too.

You may also wish to gzip your tar file. This compresses your file, and addds a .gz extension. You say something like gzip p1.tar and it creates p1.tar.gz. You can uncompress it by saying gunzip p1.tar.gz.

Deleting Files Accidentally

Due to the extreme size of executables, students are having to be more careful to delete unnecessary files. This can cause problems, as files may be deleted that you did not mean to delete.

As a precaution:

Extensions are unlikely to be given for anyone who accidentally deletes files. You can ask, but we reserve the right to refuse. So be extremely careful.

ladebug

ladebug is the debugger for cxx. There is a tutorial on it. Please read it. Learn to use it for core dumps, etc. In particular, if you have compiled with the -g option, run:
ladebug p3 core
and type "where" to indicate what happened. This will print the stack, where main() appears at the bottom. You should look at the line numbers and the arguments. Pay close attention to 0x0 which indicates a NULL pointer. Often, core dumps occur when you go out of bounds on an array or linked list, and perform some operation on a NULL pointer or invalid memory.

Unfortunately, rathet than indicate that this operation is happening on invalid memory, it prints that the operation has core dumped. If the method is particularly simple, you may need to look at what calls the method to debug it.

README

Submit a README that includes an explanation of the remove method you used in your BST.

Testing Tar Files

Prior to submitting your files, you are expected to test your tar files. To do so:

  1. Create a subdirectory. Make sure it is empty.
  2. Copy your tarfile into that directory.
  3. Copy any files from the posting account, as needed, such as the primary input and primary output.
  4. Untar your file.
  5. Run "make p3" on the file.
  6. Redirect the primary input into your program, and redirect the output into some file like "my.output".
  7. Run diff -bwi between your files and ours. If the only difference is blank lines, then you should be ready to submit.
You may need to remove .o files and executables elsewhere, so you have enough space to do this testing.

A successful SUBMISSION of your tar file does NOT always guarantee you have passed the primary input

This is why you should test your tarfile prior to submission.

How to Submit Your Project

In order to successfully submit your project, it must pass the primary input and produce the primary output. The primary input will be sent to your project using input redirection.

   p3 < primary.input
Your program MUST produce the executable p3, EXACTLY, when the command "make p3" is run. Thus, you must use a makefile named exactly "Makefile".

Your program must use cxx with the options -w0 -std strict_ansi. Unfortunately, while we have aliased this for you, it doesn't always work with Makefile, so use the full name in your makefiles.

We will use "diff -bwi" to test your code. This ignores case, treats N blanks as 1 blank, treats N blank lines as 1 blank line. We will also strip all blank lines from your input when matching to ours. However, diff is sensitive to punctuation, number of dashes, etc. so you should attempt to make your output match ours as closely as possible otherwise you may not be able to submit your program. If this is the case (that your program does not submit) you must fix your code until the output it produces matches that of the primary output. Note: "hardcoding" output is a violation of the University's Code of Academic Integrity.

To submit your project you must first combine the following files (and only these files) into a single tar file using the Unix tar command:

You may name your tarfile anything you want, but p3.tar is the suggested name.

NOTE! You should make a backup copy of all your files BEFORE attempting to create your tarfile!!!! You have been warned.

After creating the tar file you should submit that one file using the following command:

submit p3.tar 3
where p3.tar can be replaced by whichever tar file you have created, and 3 refers to the current project,

See the class syllabus for policies concerning email
Last Modified: Mon Mar 18 20:39:55 EST 2002
left up down right home