Lab #1: Snake


Due: Wednesday, July 9th, 2008 at 11:59PM


Zip file with source files, documentation, &c.
Browsable version of the files above

Below here are the two testers for this lab. They are JUnit tests and you must pass all of them in order to get a perfect score.
HashSetTest.java
ArrayQueueTest.java

In this homework, we will focus on data structures and you are responsible for their (correct) implementation. You will implement the queue data structure, which allows FIFO access. You will also implement the hashtable data structure, which implements the dictionary or associative array abstract data type. These data structures serve as the core of the snake game.

Goals:

The Queue: 40 points

The first data structure to implement is the queue. You will be implementing the Java interface Queue. The queue is used to represent the points in the snake. The snake grows at the head and shrinks at the tail, a FIFO access method. The Queue class uses a feature of Java called generics. You may want to get familiar with the Java implementation of generics.

Some notes about this implementation:

The HashSet: 40 points

Java has a useful class called HashSet, a Set that implements constant time add, remove and contains operations. The data structure is a hashtable. You will be implementing your own version of HashSet in MyHashSet.java. In snake, the hashset is used to represent a set of points. We will want to test if a given point is in that set. For example, we need to know if the snake's head is at a food item to see if it should eat the item. Since many such calls need to be made, a constant time data structure is important.

Common Pitfalls and Clarifications

Playing Snake

To play the game of Snake you just need to run the main method in Gui: java Gui. You can press space to begin a game. the red circles are the snake and the blue squares food. To change the direction the snake moves, use the arrow keys.

Coding Style: 10 points

It should go without saying that your submission must have good style. This is needed so that the TAs can understand your code and give you partial credit. It's also a good habit.

Unit Testing: 10 points

As you know, we test your labs very thoroughly using a set of unit tests via JUnit. You'll certainly want to do the same -- or you might be very surprised.

Just to make sure you get off to a good start with the first lab, we're going to grade your test suite's thoroughness, utility and correctness.