CSCI 1321 (Principles of Algorithm Design II), Fall 2003:
Homework 7

Credit:
Design 20 points; code 40 points.

Overview

By now your game should be playable, with all the major functionality implemented. This homework is something of a tangent; the goal is to write a second, more efficient priority queue and compare its performance with your first version. The needed code breaks down into two categories:

First, you are to write a second priority queue class that uses a heap (as discussed in class, using an array or Vector to store elements) rather than a sorted linked list.

Second, you are to add code to your game that will allow you to compare the performance of the two implementations as the number of game entities in the queue varies. To do this, you need to do several things: create a ``dummy'' game entity class so you can put arbitrarily many entities in the priority queue, change your main class to accept two command-line arguments that specify which implementation to use and how many of these dummy entities to add, and change your player class to print out some information that will allow you to see how performance varies based on the choice of priority queue implementation and the number of dummy entities.

So you need to do the following:

You can now run your game with different values of the two command-line arguments and see how performance changes.

Design

The design for this assignment will include descriptions of the new classes you will write (priority queue and dummy game entity), revised descriptions of classes you modify, and a UML diagram showing how all your classes fit together. As before, for the design step the code doesn't have to be complete, but the comments should describe what you plan to do.

Code

For the code part of this assignment, I want you to do two things. One is to write code as described above. The second is to collect and plot timing information that shows how, for each version of the priority, performance (time for 100 calls to player's update method) changes as the number of dummy entities increases. You will have to experiment a little to see what number of entities is needed to get meaningful results. Start with a small number (say 10), and then increase it by factors of 2 or 10 until you see performance differences. What you should see is that for $ n$ entities the time for the linked-list version is roughly proportional to $ n^2$, while for the heap version time is roughly proportional to $ n \log n$.

Details

What files do I need?

You will need

As before, you will probably find the project API and the Java 1.4 API (linked from the course ``Useful links'' page) useful.

You can use the Together project you set up for Homework 6, but for this assignment it's probably a particularly good idea to set up a new project, because you will be adding code that does not need to appear in your final game.

Completing the design step

Once you have your project set up and your classes and modifications outlined (i.e., defined in at least the skeleton form described earlier), use the ``generate HTML documentation'' feature of Together to generate documentation, putting it in the proper directory as described in the overall ``Project Description'' document. (If this doesn't work for you, you can use the javadoc command instead, though it won't automatically include your UML diagram. See ``Java Without an IDE'' for details. This page is also linked from the ``Useful links'' page.) Turn in your design as described in the ``Project Description'' document.

Completing the code step

For this step, fill in the bodies of the methods and classes you designed for this homework. Make sure your code compiles and the added features do what they're supposed to do. Also collect timing information as described above and create two graphs showing how time for 100 updates relates to number of dummy entities. You can do this by hand or using your favorite graph-plotting program.

When you're happy with how your code works, generate a final version of your documentation and turn in the code as described in the ``Project Description'' document. For this assignment, you will be turning in all your source-code (.java) files, plus possibly a file saved from the screen editor -- basically, everything I need to recompile and run your game. You do not need to send me .class files or the files that contain your Together project (*.tpr, etc.). Also turn in hard copy of your two plots.



Berna Massingill
2003-11-18