CSC234 - Project 4
TopSpin

Assigned March 3th 1 p.m.
Due March 10th 1 p.m.


Overview

In this project, you will implement the TopSpin puzzle from Binary Arts, now known as ThinkFun. We will be using our two modes of implementation for lists of objects, arrays and linked lists. Your implementations will act like the puzzle above.

TopSpin Interface

public interface TopSpin {

    // Shift the pieces one space to the left
    public void shiftLeft();

    // Shift the pieces one space to the right
    public void shiftRight();

    // Reverses the pieces currently inside the spin mechanism, such that
    // the first and last are swapped, etc.
    public void spin();

    // Returns true if the puzzle is solved, such that the pieces are in numerical order.
    public boolean isSolved();

}

Both implementations below should have a constructor that creates the TopSpin object with size numbers, and a spin mechanism of spinSize.

    public TopSpin(int size, int spinSize)

Your numbers should start at 1. size must be at least 1, and spinSize must be less than or equal to size, otherwise, an InvalidTopSpinException should be thrown.

You also need to override the toString method within each implementation, as specified here:

    // Display the TopSpin game to the user, starting with the piece in the first slot of the
    // spin mechanism, and clearly denoting the spin mechanism.  For example, 
    // the initial game for size 20 and spinSize 4 should look like:
    //
    // |-------------|
    // |  1  2  3  4 | 5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
    // |-------------|
    //
    public String toString()

Array Implementation

Your first implementation of the TopSpin interface should use an array as the basis of the TopSpin game. Devise an efficient implementation based on what we have studied about queues, stacks and lists, each of which generally included additional integer components to track the state of the collection. This class will be written in the ArrayTopSpin.java.

Circular Doubly Linked List Implementation

Your second implementation of the TopSpin interface should use the ideas from linked Lists as the basis of the TopSpin game. Devise an efficient implementation based on what we have studied about queues, stack and lists and the pointer manipulation involved. This class will be written in the LLTopSpin.java.

Doubly Linked List Node Implementation

You must use the DoublyLinkedNode as described in the text on page 160 in the text in your above implementation of the Circular Doubly Linked List implementation.

InvalidTopSpinException

This exception is needed for the constructor of your TopSpin implementations. It should inherit from RunTimeException and have an empty body.

Execution

The main method of your implementations should begin by ask the user the size and spinSize of a TopSpin object and then create it. The program should then ask the user how many random moves to make to set up the puzzle, and make that many random moves. A random move consists of shifting left 1 to 19 pieces, followed by a spin. The shift is uniformly chosen from all possible shifts.

The user is then repeatedly presented the puzzle state and a menu which asks if they want to

  1. Shift
  2. Spin
  3. Quit
If the user says Shift, prompt the user for the number of shifts, and the direction of the shift, then execute the requested shift.

If the user says Spin, execute the spin.

If the user says Quit, exit the loop and finish the program.

If the user solves the puzzle, display the current game and the message "CONGRATULATIONS!" to the user, then exit the loop and finish the program.

This method is found in the TopSpinTester.java file.

What to turn in

  1. TopSpin.java
  2. ArrayTopSpin.java
  3. LLTopSpin.java
  4. DoublyLinkedNode.java
  5. InvalidTopSpinException.java
  6. TopSpinTester.java
To hand in your Project 3 files, follow the steps listed below from the Wright Lab computers:
  1. Open the Terminal application.
  2. SSH with ssh username@cs.centenary.edu to connect with the cs server.
  3. Type in your password.
  4. Make a new directory with mkdir csc234/project3
  5. Log out of the cs server with logout
  6. Change to the directory where you have your files on the local computer.
  7. Securely copy your files to your directory with scp filenames username@cs.centenary.edu:"csc234/project3"

© Mark Goadrich 2009, Centenary College of Louisiana