Hi There!

I'm Dan Schlegel, an Associate Professor in the Computer Science Department at SUNY Oswego

Assignment 6

In this assignment you will implement some cheat codes in your game which will allow you to see the contents of rooms you are not currently in. To do so, you will make use of the BST which we have been writing in class. Specifically, you should:

  • Begin with the BST.java file from class (posted on the course GitHub page).
  • Modify the BST and Node classes to have both a key and a value. The key is used to find the Node, the value is what is returned when the node is found. (Note that while the key must implement Comparable, the value need not.) The declaration of your BST class might change to something like:
    public class BST <K extends Comparable<K>, V> { … }
    Modify the BST class as necessary so that insertion takes both a key and value, and so that the value is returned from a find operation on the key.
  • Implement the remove method for BSTs as discussed in class.
  • Write some JUnit tests to ensure your BST is working as you expect. Be sure to test insert, find, and remove.

Once you’ve finished with your BST, use it to store Rooms in your game. Use the room name as the key, and the Room object itself as the value. This will allow you to look up a room by its name without iterating through the whole list of Rooms!

You will then modify your Player class to accept the following commands:

cheatmode – enables the below two options.
look:[roomname] – prints out the contents of [roomname] by looking up the Room in the BST using the search method.
look:all – prints out the contents of all rooms, printed in alphabetical order by room name using an in-order traversal of the BST.
nocheatmode – disallows the use of the above two options.

Note, if you used a two-step process to interact with Items, you may use that same process here to maintain consistency.

Be sure you write unit tests to test any new functionality you have added.

Extra Credit: You may receive up to 20% extra credit on this assignment by implementing the Iterable and Iterator interfaces on your BST in an efficient manner. This should allow walking through the data structure in order using a simple for-each style loop from outside the BST. You may not copy the contents of the BST to a different data structure – it must be done in place.