Harvey Mudd College

Computer Science 60

Fall 1997

Assignment 4

Due Saturday 1 November 1997

Gradual Insanity

This assignment is 60 points of your overall grade.

Instant InsanityTM was a popular commercial puzzle of the 60's, before Rubik's Cube. Gradual InsanityTM is a puzzle, shown below and invented by your instructor, which is more akin to Rubik's Cube in its working than Instant Insanity. (The title is supposed to refer to the effect on the user, not the programmer.) This assignment involves implementing a portion of the Gradual Insanity puzzle as a JavaTM applet using object-oriented programming. Since the purpose is to learn about object-oriented programming, submissions must be object-oriented in a sense to be described in order to be considered correct.

Link to an actual Gradual Insanity applet.

(Note: Depending on your platform and browser, the applet may or may not work well. Please let me know whether it does or doesn't on your particular platform, not that I can do much about it.)

In Gradual Insanity, the user selects a pattern of dots from a menu of different patterns. The patterns are identified by the line of colored squares across the top of the applet. The pattern is scrambled using only row and column rotations as moves. The user attempts to restore the puzzle to the goal state using the same kinds of moves.

A row of the puzzle is rotated to the left or right by clicking with the mouse alongside the row to the left or right, respectively, in an area approximately where the next dot would lie. A column of the puzzle is similarly rotated up or down by clicking above or below the column with the mouse.

When, through a series of such moves, the goal is reached, the program tells the user the goal is achieved. When this happens, the corresponding element of the menu bar (the colored squares) turns black to so indicate. (However, this blackening takes place only provided that no hints were requested in the process.)

The user may, at any time, request a different pattern by clicking the menu. She then scrambles the puzzle by clicking the Scramble button. The UnDo button undoes the last move. Moves can be undone all the way back to the initial scrambled state, if desired.

The following are required for a fully compliant solution:

The following are not required, but may be added for extra credit if desired:

See me about the Hint mechanism. Do not attempt to provide a brute-force solving mechanism, as there are too many states for this to be computationally feasible.

A minimum of three classes should be used:

A skeleton applet to be provided will give you sample code for:

You are advised to implement the following constructors and methods for class Pattern early on:

Pattern(int Size)
is a constructor. Size is the number of dots on a side of the pattern, which is always square.
Pattern(Pattern original)
is another constructor, one which makes a copy of an existing pattern.
boolean equals(Pattern other)
is a method which tells whether this pattern is the same as another (you cannot simply test equality with ==, which gives equality of references, not contents).
void draw(Graphics g, int diam, int gap, int xOffset, int yOffset)
is a method which draws on a Graphics context g the pattern with a specified circle diameter, gap between circles, and offset position from the corner of the applet.
void columnUp(int j), etc.
various methods for modifying the pattern in-place.
void set(int i, int j, Color color)
void setColumn(int j, Color color), etc.
various methods for setting the colors of the pattern. Refer to the .java file which defines a Vector of patterns as a static variable.

I will provide you with a skeleton applet in /cs/cs60/a/GradualInsanity.java which will also contain a set of pattern specifications using the definition of class Pattern to be discussed presently. You will also need a .html file to run your applet with the appletviewer. Such a file is provided as /cs/cs60/a/GradualInsanity.html.

To compile and run an applet, please follow these steps on turing or orion:

javac GradualInsanity.java

appletviewer GradualInsanity.html

In order to use the appletviewer, you will need to be on a computer which supports the X window system. For example, the workstations in Beckman 102 will, but a random Windows machine or Mac might not, unless you have the software (such as Mac/X). As an alternative to the appletviewer, you can try loading your html file in a web browser. Not all browsers are able to handle Java, and some that do don't do it that well.

Other Suggestions