Computer Science 60
Principles of Computer Science
Fall 2003


Assignment 4: A taste of rex and a mouthful of Spam!
Due Monday, September 29 by 11:59 PM.

This assignment has two parts. The first part is a short programming exercise to familiarize you with rex. The second part of the assignment is to write a Spamsweeper Applet. You can do these parts of the assignment in any order - they are entirely independent of one another. See the the course web page for a reminder of how the late homework policy works.

rex!

First the rex assignment. Type rex at the prompt to enter the rex interpreter. You can exit rex at any time by pressing CTRL-D (control key and D). (By doing this, you will lose all of the functions that you defined while you were in the interpreter.) Play around with rex and get a feel of how it works. For documentation, see the rex reference guides available from the "Reference Guides" link on the course homepage. Write a function called twiddle which takes a list as input and returns a list which is identical to the input list except with the first and second items of the list exchanged. For example twiddle([1, 2, 3, 4]) should return the list [2, 1, 3, 4]. If the user provides a list of length less than 2, that's not your problem!

Once you've got the twiddle function working, exit rex and type that function definition in a file called hw4.rex. Now you can start rex back up and, at the rex prompt, type *i hw4.rex. This will load in the file (the "*i" stands for "include") and you can now use the functions that were defined in that file. Alternatively, you can type rex hw4.rex at the shell and it will start rex up with the functions defined in the file file hw4.rex. As an example, I have provided a file called length.rex in which I have defined the length function. You'll find this file in the directory /cs/cs60/assignments/assignment4/rexstuff.

Next, add the following functions to your file hw4.rex: To summarize, your final submission will contain functions twiddle, myreverse, power, and find_index all in one file called hw4.rex. Now you can use cs60submit to submit this file!

Spamsweeper!

Now for Spamsweeper! Note that the applet that you will be writing will run under most (but not all) web browsers due to incompatibilities between versions of Java. This applet DOES run under mozilla on the terminals in the CS terminal room. It also runs under many other browswers.

First, click here to see what the Spamsweeper applet will look like (more or less) when you're done. You're not required to implement the "New Game" button (that's optional bonus stuff - without this button you will simply need to restart the applet each time). Your game should otherwise be similar to this example. Specifically, your program should have the following features:

I've left the basic components of Spamsweeper, as described in class, in the directory /cs/cs60/assignments/assignment4/Spamsweeper/. Copy all of these files into your own directory. In particular, you will need to write the constructor for Gameboard.java and all of the interesting methods in Spamsweeper.java. You should compile Spamsweeper.java in the normal way. The compiler will warn you that Spamsweeper is using "deprecated methods". Ignore the warning. (It's just saying that there are other newer methods available in Java to do some of the graphics black magic that we've provided.)

To run the applet, you can simply type appletviewer Spamsweeper.html. The appletviewer will only work if you are on a terminal in the CS terminal room. The other alternative is to run the applet from your web site. You can do this as follows: Copy the Spamsweeper.html file and all the compiled files of your Spamsweeper implementation (Spamsweeper.class, Gameboard.class, Boardcell.class and any other file that ends in .class that you used in your implemenation) to the directory public_html which you'll see in your home directory on turing. Please do not put any file that ends in .java in your public_html directory. This makes your code available to the public and is thus a violation of the code sharing policy. Finally, go into your public_html directory and type "chmod ugo+rx *". This makes the applet accessible on the web. (This is OK, since only the compiled version of the code can be seen by the web, not your original source code.) Now you can run the applet by going to the website: www.cs.hmc.edu/~username/Spamsweeper.html where username is your login name on turing. Don't forget the tilde symbol before your username.

Please sumbit all of the .java files (Boardcell.java, Gameboard.java, Spamsweeper.java, Spamsweeper.html, and whatever else you add on your own).

For Totally Optional Bonus Credit create an implementation called Bonussweeper.java applet (and any other auxilliary files) which augments Spamsweeper with one or more of the following features (extra credit for each feature):

Make sure that at the top of the file Bonussweeper.java you clearly document which of these features you have added.

Last modified September 2003 by Ran Libeskind-Hadas