CMPS 161

Jonathan Finger (jono@ucsc.edu)

Kube!


Name

kube

Description

A virtual Rubiks Cube.

Compiling and running

Use compile, use:

make

To run, use:

./kube

This project was developed simultaneously on Solaris, OpenBSD, and cygwin so it can be compiled for all those systems. The makefile provided should work on the Solaris machines. If you have been profided with the windows exe, I recomend using that one. It is the fastest. You can download it here.

How to use it

The interface is fairly simple. A left click and drag will rotate the cube as a whole. A right click and drag will rotate one layer on the cube. If you are rotating a layer and release the mouse button, that layer will be rotated to the closest 90 degree angle.

The cube can be randomly scrambled and solved. You can zoom in and out, and change the speed of how fast it gets solved. Use the meny at the top to set some options about the cube color. You can also choose to use a 4x4x4 or a 5x5x5 or a 2x2x2 cube instead of the conventional 3x3x3.

How it works

The cube is made up of a cubic number of plastic pieces. Each piece has 6 faces that can be colored individually. The cube can be split up into layers. A 3x3x3 cube has 3 layers of 9 pieces each.

What is in a move

A "move" consists of a 90 degree layer rotation. A move is defined by a dimension, a layer number and a direction. The cube has different layers in the X, Y and Z dimensions. Once one of those dimensions is choosen, you must decide which layer to move in that dimension (layer number). Direction determines if a rotation is clockwise or counter clockwise.

Layer picking

When the mouse is left clicked, the program marks the closest face of a piece. The mouse should be dragged following that click. It then marks the next closest face. Once that piece is marked, the program will find the closest dimension and layer number it thinks the user wants to rotate about. As long as the mouse is still heald down, you can drag that layer in either direction.

Scrambling

The scrambler applies 20 to 65 random moves to the cube. It is not animated, so you can not watch how to solve it. If you think 65 moves is not enough you can click the "scramble" button multiple times and it will keep applying more random moves.

Solving

The cube always starts in a solved state. There is a stack that records every move from the solved state. When a new cube is created, the stack is emptied. Clickin the "solve" button, will cause the program to reverse all the moves on the stack. It does this by popping the top move from the stack and applying it to the cube with the reverse direction. It does this until the stack is empty.

Solution optimization

I created something I like to call a first degree move eliminator to optimize the cube solver. It checks to see if the user moves a layer once, and then moves the same layer in the oposite direction. That would be a reduntant move, so both of those moves would be eliminated from the stack before the solver begins its animation. This is an optimization because it reduces the amount of moves needed to solve the cube. I could add a higher degree move eliminator that would get rid of 6 move reduntancies but that was not the focus of this project. There are also other optimizations beside degree eliminators and other ways to solve the cube without reversing the steps done while scrambling it.

Additional Notes

I used a trackball from an old CMPS160 class. It can be found here: http://www.soe.ucsc.edu/classes/cmps160/Fall04/CubeViewDemo/

The program is documented where I felt it necessarry.