CSC234 - Project 3
TopSpin
Assigned March 9th 1 p.m.
Due March 16th 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, and should include
a main method for testing as described below.
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, and should include
a main method for testing as described below.
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
creating a TopSpin object of size 20 and spinSize 4. 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. Your shift should be uniformly chosen from all possible shifts.
The user is then repeatedly presented the puzzle state and a menu which asks if they want to
- Shift
- Spin
- 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.
What to turn in
- TopSpin.java
- ArrayTopSpin.java
- LLTopSpin.java
- DoublyLinkedNode.java
- InvalidTopSpinException.java
To hand in your Project 3 files, follow the steps listed below from the Wright Lab computers:
- Open the Terminal application.
- SSH with
ssh username@cs.centenary.edu
to connect with the cs server.
- Type in your password.
- Make a new directory with
mkdir csc234/project3
- Log out of the cs server with
logout
- Change to the directory where you have your files on the local computer.
- Securely copy your files to your directory with
scp filenames username@cs.centenary.edu:"csc234/project3"
© Mark Goadrich 2009, Centenary College of Louisiana