CubeTwister 2.0alpha141 2011-10-13

ch.randelshofer.rubik
Class AbstractCube

java.lang.Object
  extended by ch.randelshofer.rubik.AbstractCube
All Implemented Interfaces:
Cube, java.lang.Cloneable
Direct Known Subclasses:
Cube6, Cube7, PocketCube, ProfessorCube, RevengeCube, RubiksCube

public abstract class AbstractCube
extends java.lang.Object
implements Cube, java.lang.Cloneable

Abstract base class for classes which implement the Cube interface.

This class provides support for event listeners, and it defines the variables which hold the location and orientation of the cube parts.

Faces and Axes

This class defines the location of the six faces of the cube, as shown below:

             +---+---+---+
             |           |
             |           |
             |    1 u    |
             |           |
             |           |
 +---+---+---+---+---+---+---+---+---+---+---+---+
 |           |           |           |           |
 |           |           |           |           |
 |    3 l    |    2 f    |    0 r    |    5 b    |
 |           |           |           |           |
 |           |           |           |           |
 +---+---+---+---+---+---+---+---+---+---+---+---+
             |           |
             |           |
             |    4 d    |
             |           |
             |           |
             +---+---+---+
 
The numbers represent the ID's of the faces: 0=right, 1=up, 2=front, 3=left, 4=down, 5=back.

The face ID's are symmetric along the axis from the right-up-front corner through the left-down-back corner of the cube.

Corner parts

This class defines the initial locations and orientations of the corner parts as shown below:

             +---+---+---+
          ulb|4.0|   |2.0|ubr
             +---     ---+
             |     u     |
             +---     ---+
          ufl|6.0|   |0.0|urf
 +---+---+---+---+---+---+---+---+---+---+---+---+
 |4.1|   |6.2|6.1|   |0.2|0.1|   |2.2|2.1|   |4.2|
 +---     ---+---     ---+---     ---+---     ---+
 |     l     |     f     |     r     |     b     |
 +---     ---+---     ---+---     ---+---     ---+
 |5.2|   |7.1|7.2|   |1.1|1.2|   |3.1|3.2|   |5.1|
 +---+---+---+---+---+---+---+---+---+---+---+---+
          dlf|7.0|   |1.0|dfr
             +---     ---+
             |     d     |
             +---     ---+
          dbl|5.0|   |3.0|drb
             +---+---+---+
 

The numbers before the dots represents the ID's of the corner parts. There are 12 corner parts with ID's ranging from 0 through 11. Since a corner part is visible on three faces of the cube, the ID of each part is shown 3 times.

The numbers after the dots indicate the orientations of the corner parts. Each corner part can have three different orientations: 0=initial, 1=tilted counterclockwise and 2=titled clockwise.

The orientations of the corner parts are symmetric along the axis from the right-up-front corner through the left-down-back corner of the cube.

       +-----------+              +-----------+
      /4.0/   /2.0/|             /1.0/   /3.0/|
     +---     ---+.2            +---     ---+.2
    /     u     /|/|           /     d     /|/| 
   +---     ---+   +          +---     ---+   +
  /6.0/   /0.0/|  /|         /7.0/   /5.0/|  /|
 +---+---+---*.1  .1        +---+---+---*.1  .1 
 | .1|   | .2|/ r|/         | .1|   | .2|/ b|/
 +---     ---+   +          +---     ---+   +
 |     f     |/|/           |     l     |/|/
 +---     ---+.2            +---     ---+.2
 | .2|   | .1|/             |.2 |   | .1|/ 
 +---+---+---+              +---+---+---+
 

Here is an alternative representation of the initial locations and orientations of the corner parts as a list:

Edge parts

This class defines the orientations of the edge parts and the location of the first 12 edges. (The locations of additional edge parts are defined by subclasses):

               +----+---+----+
               |    |3.1|    |
               |    +---+    |
               +---+     +---+
             ul|6.0|  u  |0.0|ur
               +---+     +---+
               |    +---+    |
               |    |9.1|    |
 +----+---+----+----+---+----+----+---+----+----+---+----+
 |    |6.1|    |    |9.0|fu  |    |0.1|    |    |3.0|bu  |
 |    +---+    |    +---+    |    +---+    |    +---+    |
 +---+     +---+---+     +---+---+     +---+---+     +---+
 |7.0|  l  10.0|10.1  f  |1.1|1.0|  r  |4.0|4.1|  b  |7.1|
 +---+     +---+---+     +---+---+     +---+---+     +---+
 |lb  +---+  lf|    +---+    |rf  +---+  rb|    +---+    |
 |    |8.1|    |    11.0|fd  |    |2.1|    |    |5.0|bd  |
 +----+---+----+----+---+----+----+---+----+----+---+----+
               |    11.1|    |
               |    +---+    |
               +---+     +---+
             dl|8.0|  d  |2.0|dr
               +---+     +---+
               |    +---+    |
               |    |5.1|    |
               +----+---+----+
 
The numbers after the dots indicate the orientations of the edge parts. Each edge part can have two different orientations: 0=initial, 1=flipped.
               +----+---+----+
               |    |3.1|    |
               |    +---+    |
               +---+     +---+
             ul|6.0|  u  |0.0|ur
               +---+     +---+
               |    +---+    |
               |    |9.1|    |
 +----+---+----+----+---+----+----+---+----+----+---+----+
 |    |6.1|    |    |9.0|fu  |    |0.1|    |    |3.0|bu  |
 |    +---+    |    +---+    |    +---+    |    +---+    |
 +---+     +---+---+     +---+---+     +---+---+     +---+
 |7.0|  l  10.0|10.1  f  |1.1|1.0|  r  |4.0|4.1|  b  |7.1|
 +---+     +---+---+     +---+---+     +---+---+     +---+
 |lb  +---+  lf|    +---+    |rf  +---+  rb|    +---+    |
 |    |8.1|    |    11.0|fd  |    |2.1|    |    |5.0|bd  |
 +----+---+----+----+---+----+----+---+----+----+---+----+
               |    11.1|    |
               |    +---+    |
               +---+     +---+
             dl|8.0|  d  |2.0|dr
               +---+     +---+
               |    +---+    |
               |    |5.1|    |
               +----+---+----+
 

The orientations of the edge parts are symmetric along the axis from the front-up edge through the back-down edge of the cube.

       +-----------+      +-----------+
      /   / 3 /   /|      |\   \11 \   \
     +--- --- ---+ +      + +--- --- ---+
    /6.0/ u /0.0/|/|      |\|\8.0\ d \2.0\
   +--- --- ---+  4.0   10.0  +--- --- ---+
  /   / 9 /   /| |/|      |\ \|\   \ 5 \   \
 +---+-*-+---+  r  +      +  l  +---+-*-+---+
 |   |9.0|   |/| |/        \|\ \|   |5.0|   |
 +--- --- ---+  2.1        6.1  +--- --- ---+
 |10 | f | 1 |/|/            \|\| 7 | b | 4 |
 +--- --- ---+ +              + +--- --- ---+
 |   11.0|   |/                \|   |3.0|   |
 +---+---+---+                  +---+---+---+
 

Here is an alternative representation of the initial locations and orientations of the edge parts as a list:

Side parts

This class defines the orientations of the side parts as shown below (The locations of the side parts are defined by subclasses):

             +-----------+
             |     .1    |
             |   +---+ u |
             | .0| 1 |.2 |
             |   +---+   |
             |     .3    |
 +-----------+-----------+-----------+-----------+
 |     .0    |     .2    |     .3    |    .1     |
 |   +---+ l |   +---+ f |   +---+ r |   +---+ b |
 | .3| 3 |.1 | .1| 2 |.3 | .2| 0 |.0 | .0| 5 |.2 |
 |   +---+   |   +---+   |   +---+   |   +---+   |
 |     .2    |    .0     |     .1    |     .3    |
 +-----------+-----------+-----------+-----------+
             |     .0    |
             |   +---+ d |
             | .3| 4 |.1 |
             |   +---+   |
             |     .2    |
             +-----------+
 
The numbers after the dots indicate the orientations of the side parts. Each side part can have four different orientations: 0=initial, 1=tilted clockwise, 2=flipped, 3=tilted counterclockwise.

The orientations of the side parts are symmetric along the axis from the right-up-front corner through the left-down-back corner of the cube.

       +-----------+              +-----------+
      /     .1    /|             /     .1    /|
     +    ---    +r+            +    ---    +b+
    / .0/ 1 /.2 /  |           / .0/ 4 /.2 /  | 
   +    ---    +.3 +          +    ---    +.3 +
  / u   .3    / /|.0         / d   .3    / /|.0
 +---+---+---*  0  +        +---+---+---*  5  + 
 | f   .2    .2|/ /         | l   .2    .2|/ /
 +    ---    + .1+          +    ---    + .1+
 | .1| 2 |.3 |  /           | .1| 3 |.3 |  /
 +    ---    + +            +    ---    + +
 |     .0    |/             |     .0    |/ 
 +---+---+---+              +---+---+---+
 

Here is an alternative representation of the initial locations and orientations of the side parts as a list:

Version:
5.0 2010-05-03 Added support for transform type.
4.0.1 2008-01-06 Fixed twist angle of edge 'dl'.
4.0 2007-12-27 Changed the location and orientation of the parts so that they are symmetric to the axis passing from the right-up-front corner through the left-down-back corner.
3.0 2007-11-15 Upgraded to Java 1.4. Removed method toPermutationString.
2.0 2004-10-24 Reworked to support cubes ranging from 2 to 5 layers. Renamed from RubiksCubeCore to AbstractCube.
1.4.1 2004-09-18 Fixed orientation changes of side parts in method twistMiddleRightClockwise.
1.4 2004-02-23 Support for two-layer and slice twists added.
1.3.1 2003-07-18 Method getCenterSide(int) added.
1.3 2002-05-06 Method getOrder added. Output of undesired line breaks in methods toPermutationString() and toPermutationString(ScriptParser) fixed. Method getParityInfo() replaced by method getParityInfo(). Method isSolved() added.
1.2 2001-08-14 Twist methods are now private.
1.1 2001-07-23 Adapted to JDK 1.3
1.0 2001-02-03 Reworked.
0.0 1999-12-31 Draft.
Author:
Werner Randelshofer

Nested Class Summary
protected static class AbstractCube.TransformType
          Transformation types of the cube.
 
Field Summary
static int CENTER_PART
          Identifier for the center part type.
protected  int[][] CENTER_TO_SIDE_MAP
          This is used for mapping center part orientations to the 6 sides of the cube.
static int CORNER_PART
          Identifier for the corner part type.
protected static int[][][][] CORNER_SWIPE_TABLE
           
protected static int[][] CORNER_TO_FACE_MAP
          This array maps corner parts to the six faces of the cube.
protected  int[] cornerLoc
          This array holds the locations of the corner parts.
protected  int[] cornerOrient
          This array holds the orientations of the corner parts.
static int EDGE_PART
          Identifier for the edge part type.
protected static int[][] EDGE_TO_ANGLE_MAP
          This array maps edge parts to rotation angles over the three axes of the cube.
protected static int[] EDGE_TO_AXIS_MAP
          This array maps edge parts to the three axes of the cube.
protected static int[][] EDGE_TO_FACE_MAP
          This array maps edge parts to the 6 faces of the cube.
protected  int[] edgeLoc
          This array holds the locations of the edge parts.
protected  int[] edgeOrient
          This array holds the orientations of the edge parts.
protected  int layerCount
          Number of layers on the x, y and z axis.
static int NUMBER_OF_CORNER_PARTS
          Holds the number of corner parts, which is 8.
static int SIDE_PART
          Identifier for the side part type.
protected  int[] sideLoc
          This array holds the locations of the side parts.
protected  int[] sideOrient
          This array holds the orientations of the side parts.
protected  int transformAngle
          If transformType is SINGLE_AXIS_TRANSFORM, this field holds the transformation angle.
protected  int transformAxis
          If transformType is SINGLE_AXIS_TRANSFORM, this field holds the transformation axis.
protected  int transformMask
          If transformType is SINGLE_AXIS_TRANSFORM, this field holds the transformation mask.
protected  AbstractCube.TransformType transformType
          This field caches the current transformation type of the cube.
 
Constructor Summary
AbstractCube()
          Creates a new instance.
AbstractCube(int layerCount)
          Creates a new instance.
 
Method Summary
 void addCubeListener(CubeListener l)
          Adds a listener for CubeEvent's.
 java.lang.Object clone()
          Clones the cube.
 boolean equals(java.lang.Object o)
          Compares two cubes for equality.
protected  void fireCubeChanged(CubeEvent event)
          Notify all listeners that have registered interest for notification on this event type.
protected  void fireCubeTwisted(CubeEvent event)
          Notify all listeners that have registered interest for notification on this event type.
protected  void fourCycle(int[] loc, int l1, int l2, int l3, int l4, int[] orient, int o1, int o2, int o3, int o4, int modulo)
          Performs a four cycle permutation and orientation change.
 int getCornerAt(int location)
          Gets the corner part at the specified location.
 int getCornerCount()
          Returns the number of corner parts.
 int getCornerLocation(int corner)
          Gets the location of the specified corner part.
 int[] getCornerLocations()
          Returns the locations of all corner parts.
 int getCornerOrientation(int corner)
          Gets the orientation of the specified corner part.
 int[] getCornerOrientations()
          Returns the orientations of all corner parts.
 int getCubeOrientation()
          Returns the orientation of the whole cube.
 int getEdgeAt(int location)
          Gets the edge part at the specified location.
 int getEdgeCount()
          Returns the number of edge parts.
 int getEdgeLocation(int edge)
          Gets the location of the specified edge part.
 int[] getEdgeLocations()
          Returns the locations of all edge parts.
 int getEdgeOrientation(int edge)
          Gets the orientation of the specified edge part.
 int[] getEdgeOrientations()
          Returns the orientations of all edge parts.
 int getLayerCount()
          Returns the number of layers on the x, y and z axis.
 int getPartAngle(int part, int orientation)
          Returns the angle which is clockwise for the specified part orientation.
 int getPartAt(int location)
          Returns the location of the specified part.
 int getPartAxis(int part, int orientation)
          Returns the current axis on which the orientation of the part lies.
 int getPartCount()
          Returns the number of cube parts.
 int getPartFace(int part, int orient)
          Returns the face at which the indicated orientation of the part is located.
abstract  int getPartLayerMask(int part, int orientation)
          Returns the current layer mask on which the orientation of the part lies.
 int getPartLocation(int part)
          Returns the location of the specified part.
 int getPartOrientation(int part)
          Returns the orientation of the specified part.
 int getPartType(int part)
          Returns the type of the specified part.
 int getSideAt(int location)
          Gets the side part at the specified location.
 int getSideCount()
          Returns the number of side parts.
 int getSideLocation(int side)
          Gets the location of the specified side part.
 int[] getSideLocations()
          Returns the locations of all side parts.
 int getSideOrientation(int side)
          Gets the orientation of the specified side part.
 int[] getSideOrientations()
          Returns the orientations of all side parts.
 int[] getUnsolvedParts()
          Returns an array of part ID's, for each part in this cube, which is not at its initial location or has not its initial orientation.
 int hashCode()
          Returns the hash code for the cube.
 boolean isQuiet()
           
 boolean isSolved()
          Returns true if the cube is in its ordered (solved) state.
 void removeCubeListener(CubeListener l)
          Removes a listener for CubeEvent's.
 void reset()
          Resets the cube to its initial (ordered) state.
 void setCorners(int[] locations, int[] orientations)
          Sets the locations and orientations of all corner parts.
 void setEdges(int[] locations, int[] orientations)
          Sets the locations and orientations of all edge parts.
 void setQuiet(boolean b)
          Set this to false to prevent notification of listeners.
 void setSides(int[] locations, int[] orientations)
          Sets the locations and orientations of all side parts.
 void setTo(Cube tx)
          Copies the permutation of the specified cube to this cube.
 void transform(Cube tx)
          Applies the permutation of the specified cube to this cube and fires a cubeChanged event.
 void transform(int axis, int layerMask, int angle)
          Transforms the cube and fires a cubeTwisted event.
protected abstract  void transform0(int axis, int layerMask, int angle)
          Transforms the cube and fires a cubeTwisted event.
protected  void twoCycle(int[] loc, int l1, int l2, int[] orient, int o1, int o2, int modulo)
          Performs a two cycle permutation and orientation change.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ch.randelshofer.rubik.Cube
getPartSwipeAngle, getPartSwipeAxis, getPartSwipeLayerMask, setToStickers, toStickers
 

Field Detail

CORNER_PART

public static final int CORNER_PART
Identifier for the corner part type.

See Also:
Constant Field Values

EDGE_PART

public static final int EDGE_PART
Identifier for the edge part type.

See Also:
Constant Field Values

SIDE_PART

public static final int SIDE_PART
Identifier for the side part type.

See Also:
Constant Field Values

CENTER_PART

public static final int CENTER_PART
Identifier for the center part type.

See Also:
Constant Field Values

NUMBER_OF_CORNER_PARTS

public static final int NUMBER_OF_CORNER_PARTS
Holds the number of corner parts, which is 8.

See Also:
Constant Field Values

layerCount

protected int layerCount
Number of layers on the x, y and z axis.


cornerLoc

protected int[] cornerLoc
This array holds the locations of the corner parts.

The value of an array element represents the ID of a corner part. The value must be element of {0..7}.

Each array element has a unique value.

Initially each corner part with ID i is located at cornerLoc[i].


cornerOrient

protected int[] cornerOrient
This array holds the orientations of the corner parts.

The value of an array element represents the orientation of a corner part. The value must be element of {0, 1, 2}.

Multiple array elements can have the same value.

Initially each corner part is oriented at orientation 0.


edgeLoc

protected int[] edgeLoc
This array holds the locations of the edge parts.

The value of an array element represents the ID of an edge part. The value must be element of {0..(n-1)}. Whereas n is the number of edge parts.

Each array element has a unique value.

Initially each edge part with ID i is located at edgeLoc[i].


edgeOrient

protected int[] edgeOrient
This array holds the orientations of the edge parts.

The value of an array element represents the orientation of an edge part. The value must be element of {0, 1}.

Multiple array elements can have the same value.

Initially each edge part is oriented at orientation 0.


sideLoc

protected int[] sideLoc
This array holds the locations of the side parts.

The value of an array element represents the ID of a side part. The value must be element of {0..(n-1)}. Whereas n is the number of side parts.

Each array element has a unique value.

Initially each side part with ID i is located at sideLoc[i].


sideOrient

protected int[] sideOrient
This array holds the orientations of the side parts.

The value of an array element represents the orientation of a side part. The value must be element of {0, 1, 2, 4}.

Multiple array elements can have the same value.

Initially each side part is oriented at orientation 0.


transformType

protected AbstractCube.TransformType transformType
This field caches the current transformation type of the cube.


transformAxis

protected int transformAxis
If transformType is SINGLE_AXIS_TRANSFORM, this field holds the transformation axis. Otherwise, the value of this field is undefined.


transformAngle

protected int transformAngle
If transformType is SINGLE_AXIS_TRANSFORM, this field holds the transformation angle. Otherwise, the value of this field is undefined.


transformMask

protected int transformMask
If transformType is SINGLE_AXIS_TRANSFORM, this field holds the transformation mask. Otherwise, the value of this field is undefined.


CORNER_TO_FACE_MAP

protected static final int[][] CORNER_TO_FACE_MAP
This array maps corner parts to the six faces of the cube.

The first dimension of the array represents the locations, the second dimension the orientations. The values represent the 6 faces: 0=right, 1=up, 2=front, 3=left, 4=down, 5=back.


EDGE_TO_AXIS_MAP

protected static final int[] EDGE_TO_AXIS_MAP
This array maps edge parts to the three axes of the cube.

The index represents the ID of an edge. The values represent the 3 axes 0=x, 1=y and 2=z.


EDGE_TO_ANGLE_MAP

protected static final int[][] EDGE_TO_ANGLE_MAP
This array maps edge parts to rotation angles over the three axes of the cube.

The index for the first dimension represents the location, the index for the second dimension the orientation. The value 1 represents clockwise angle, -1 represents counterclockwise angle.


EDGE_TO_FACE_MAP

protected static final int[][] EDGE_TO_FACE_MAP
This array maps edge parts to the 6 faces of the cube.

The index for the first dimension represents the location, the index for the second dimension the orientation. The values represent the 6 faces: 0=right, 1=up, 2=front, 3=left, 4=down, 5=back.


CENTER_TO_SIDE_MAP

protected int[][] CENTER_TO_SIDE_MAP
This is used for mapping center part orientations to the 6 sides of the cube.

The index for the first dimension represents the location, the index for the second dimension the orientation. The values represent the 6 sides.


CORNER_SWIPE_TABLE

protected static final int[][][][] CORNER_SWIPE_TABLE
Constructor Detail

AbstractCube

public AbstractCube()
Creates a new instance.


AbstractCube

public AbstractCube(int layerCount)
Creates a new instance.

Parameters:
layerCount - number of layers on the x, y and z axis.
Throws:
java.lang.IllegalArgumentException - if the layour count is smaller than 2.
Method Detail

equals

public boolean equals(java.lang.Object o)
Compares two cubes for equality.

Specified by:
equals in interface Cube
Overrides:
equals in class java.lang.Object
Returns:
Returns true if the Cube is equal.
See Also:
Cube.hashCode()

hashCode

public int hashCode()
Returns the hash code for the cube.

Specified by:
hashCode in interface Cube
Overrides:
hashCode in class java.lang.Object
See Also:
Cube.equals(java.lang.Object)

reset

public void reset()
Resets the cube to its initial (ordered) state.

Specified by:
reset in interface Cube
See Also:
Cube.isSolved()

isSolved

public boolean isSolved()
Returns true if the cube is in its ordered (solved) state.

Specified by:
isSolved in interface Cube

addCubeListener

public void addCubeListener(CubeListener l)
Adds a listener for CubeEvent's.

Specified by:
addCubeListener in interface Cube

removeCubeListener

public void removeCubeListener(CubeListener l)
Removes a listener for CubeEvent's.

Specified by:
removeCubeListener in interface Cube

fireCubeTwisted

protected void fireCubeTwisted(CubeEvent event)
Notify all listeners that have registered interest for notification on this event type.


fireCubeChanged

protected void fireCubeChanged(CubeEvent event)
Notify all listeners that have registered interest for notification on this event type.


setQuiet

public void setQuiet(boolean b)
Set this to false to prevent notification of listeners. Setting this to true will fire a cubeChanged event.

Specified by:
setQuiet in interface Cube

isQuiet

public boolean isQuiet()

getCornerLocations

public int[] getCornerLocations()
Returns the locations of all corner parts.

Specified by:
getCornerLocations in interface Cube
Returns:
An array with a permutation of the numbers 0 through getCornerCount() - 1.

getCornerOrientations

public int[] getCornerOrientations()
Returns the orientations of all corner parts.

Specified by:
getCornerOrientations in interface Cube
Returns:
An array of orientations. The array elements can have the values 0, 1, and 2.

setCorners

public void setCorners(int[] locations,
                       int[] orientations)
Sets the locations and orientations of all corner parts.

Specified by:
setCorners in interface Cube
Parameters:
locations - An array with a permutaton of the numbers 0 through getCornerCount() - 1.
orientations - An array with only the values 0, 1 and 2. The length of the array must be getCornerCount().

getCornerAt

public int getCornerAt(int location)
Gets the corner part at the specified location.

Specified by:
getCornerAt in interface Cube
Returns:
A value in the range from 0 through getCornerCount() - 1.

getCornerLocation

public int getCornerLocation(int corner)
Gets the location of the specified corner part.

Specified by:
getCornerLocation in interface Cube
Returns:
A value in the range from 0 through getCornerCount() - 1.

getCornerCount

public int getCornerCount()
Returns the number of corner parts.

Specified by:
getCornerCount in interface Cube
Returns:
Always returns 8.

getEdgeCount

public int getEdgeCount()
Returns the number of edge parts.

Specified by:
getEdgeCount in interface Cube
Returns:
0 for a cube with 2 layers, 12 for a cube with 3 layers, 24 for a cube with 4 layers, ... .

getSideCount

public int getSideCount()
Returns the number of side parts.

Specified by:
getSideCount in interface Cube
Returns:
0 for a cube with 2 layers, 6 for a cube with 3 layers, 24 for a cube with 4 layers, ... .

getCornerOrientation

public int getCornerOrientation(int corner)
Gets the orientation of the specified corner part.

Specified by:
getCornerOrientation in interface Cube
Returns:
0, 1 or 2.

getEdgeLocations

public int[] getEdgeLocations()
Returns the locations of all edge parts.

Specified by:
getEdgeLocations in interface Cube
Returns:
An array with a permutation of the numbers 0 through getEdgeCount() - 1.

getEdgeOrientations

public int[] getEdgeOrientations()
Returns the orientations of all edge parts.

Specified by:
getEdgeOrientations in interface Cube
Returns:
An array of orientations. The array elements can have the values 0, and 1.

setEdges

public void setEdges(int[] locations,
                     int[] orientations)
Sets the locations and orientations of all edge parts.

Specified by:
setEdges in interface Cube
Parameters:
locations - An array with a permutaton of the numbers 0 through getEdgeCount() - 1.
orientations - An array with only the values 0, and 1. The length of the array must be getEdgeCount().

getEdgeAt

public int getEdgeAt(int location)
Gets the edge part at the specified location.

Specified by:
getEdgeAt in interface Cube
Returns:
A value in the range from 0 through getEdgeCount() - 1.

getEdgeLocation

public int getEdgeLocation(int edge)
Gets the location of the specified edge part.

Specified by:
getEdgeLocation in interface Cube
Returns:
A value in the range from 0 through getEdgeCount() - 1.

getEdgeOrientation

public int getEdgeOrientation(int edge)
Gets the orientation of the specified edge part.

Specified by:
getEdgeOrientation in interface Cube
Returns:
0 or 1.

getSideLocations

public int[] getSideLocations()
Returns the locations of all side parts.

Specified by:
getSideLocations in interface Cube
Returns:
An array with a permutation of the numbers 0 through getSideCount() - 1.

getSideOrientations

public int[] getSideOrientations()
Returns the orientations of all side parts.

Specified by:
getSideOrientations in interface Cube
Returns:
An array of orientations. The array elements can have the values 0, 1, 2 and 3.

setSides

public void setSides(int[] locations,
                     int[] orientations)
Sets the locations and orientations of all side parts.

Specified by:
setSides in interface Cube
Parameters:
locations - An array with a permutaton of the numbers 0 through getSideCount() - 1.
orientations - An array with only the values 0, 1, 2, and 3. The length of the array must be getSideCount().

getSideAt

public int getSideAt(int location)
Gets the side part at the specified location.

Specified by:
getSideAt in interface Cube
Returns:
A value in the range from 0 through getSideCount() - 1.

getSideLocation

public int getSideLocation(int side)
Gets the location of the specified side part.

Specified by:
getSideLocation in interface Cube
Returns:
A value in the range from 0 through getSideCount() - 1.

getSideOrientation

public int getSideOrientation(int side)
Gets the orientation of the specified side part.

Specified by:
getSideOrientation in interface Cube
Returns:
0, 1, 2 or 3.

setTo

public void setTo(Cube tx)
Copies the permutation of the specified cube to this cube.

Specified by:
setTo in interface Cube
Parameters:
tx - The cube to be applied to this cube object.

getLayerCount

public int getLayerCount()
Returns the number of layers on the x, y and z axis.

Specified by:
getLayerCount in interface Cube
Returns:
A value from 2 through 32.

transform

public final void transform(int axis,
                            int layerMask,
                            int angle)
Transforms the cube and fires a cubeTwisted event. The actual work is done in method transform0.

Specified by:
transform in interface Cube
Parameters:
axis - 0=x, 1=y, 2=z axis.
layerMask - A bitmask specifying the layers to be transformed. The size of the layer mask depends on the value returned by getLayerCount(axis). For a 3x3x3 cube, the layer mask has the following meaning: 7=rotate the whole cube;
1=twist slice near the axis (left, bottom, behind)
2=twist slice in the middle of the axis
4=twist slice far away from the axis (right, top, front)
angle - positive values=clockwise rotation
negative values=counterclockwise rotation
1=90 degrees
2=180 degrees
See Also:
getLayerCount()

transform0

protected abstract void transform0(int axis,
                                   int layerMask,
                                   int angle)
Transforms the cube and fires a cubeTwisted event.

Parameters:
axis - 0=x, 1=y, 2=z axis.
layerMask - A bitmask specifying the layers to be transformed. The size of the layer mask depends on the value returned by getLayerCount(axis). For a 3x3x3 cube, the layer mask has the following meaning: 7=rotate the whole cube;
1=twist slice near the axis (left, bottom, behind)
2=twist slice in the middle of the axis
4=twist slice far away from the axis (right, top, front)
angle - positive values=clockwise rotation
negative values=counterclockwise rotation
1=90 degrees
2=180 degrees
See Also:
getLayerCount()

transform

public void transform(Cube tx)
Applies the permutation of the specified cube to this cube and fires a cubeChanged event.

Specified by:
transform in interface Cube
Parameters:
tx - The cube to be used to transform this cube object.
Throws:
InvalidArgumentException, - if one or more of the values returned by tx.getLayourCount(axis) are different from this cube.
See Also:
getLayerCount()

twoCycle

protected void twoCycle(int[] loc,
                        int l1,
                        int l2,
                        int[] orient,
                        int o1,
                        int o2,
                        int modulo)
Performs a two cycle permutation and orientation change.


fourCycle

protected void fourCycle(int[] loc,
                         int l1,
                         int l2,
                         int l3,
                         int l4,
                         int[] orient,
                         int o1,
                         int o2,
                         int o3,
                         int o4,
                         int modulo)
Performs a four cycle permutation and orientation change.


getPartFace

public int getPartFace(int part,
                       int orient)
Returns the face at which the indicated orientation of the part is located.

Specified by:
getPartFace in interface Cube
Returns:
A value in the range from 0 through 5.

getPartOrientation

public int getPartOrientation(int part)
Returns the orientation of the specified part.

Specified by:
getPartOrientation in interface Cube
Returns:
Returns 0..2 for a corner part, 0..1 for an edge part, 0..3 for a side part, 0..24 for the center part.

getPartLocation

public int getPartLocation(int part)
Returns the location of the specified part.

Specified by:
getPartLocation in interface Cube
Returns:
Returns the location for a corner part, location + getCornerPartCount() for an edge part, location + getCornerPartCount() + getEdgePartCount() for a side part, getPartCount() - 1 for the center part.

getPartAxis

public int getPartAxis(int part,
                       int orientation)
Returns the current axis on which the orientation of the part lies. Returns -1 if the part lies on none or multiple axis (the center part).

Specified by:
getPartAxis in interface Cube
Returns:
0 for the x-axis, 1 for the y-axis, 2 for the z-axis. -1 if the part lies on none or multiple axis (the center part).

getPartAngle

public int getPartAngle(int part,
                        int orientation)
Returns the angle which is clockwise for the specified part orientation. Returns 1 or -1. Returns 0 if the direction can not be determined (the center part).

Specified by:
getPartAngle in interface Cube

getPartLayerMask

public abstract int getPartLayerMask(int part,
                                     int orientation)
Returns the current layer mask on which the orientation of the part lies. Returns 0 if no mask can be determined (the center part).

Specified by:
getPartLayerMask in interface Cube
Returns:
2^layer number

getPartType

public int getPartType(int part)
Returns the type of the specified part.

Specified by:
getPartType in interface Cube
Returns:
0 for corner parts, 1 for edge parts, 2 for side parts, 3 for the center part.

getPartAt

public int getPartAt(int location)
Returns the location of the specified part.

Specified by:
getPartAt in interface Cube

getCubeOrientation

public int getCubeOrientation()
Returns the orientation of the whole cube.

Specified by:
getCubeOrientation in interface Cube
Returns:
The orientation of the cube, or -1 if the orientation can not be determined.

clone

public java.lang.Object clone()
Description copied from interface: Cube
Clones the cube.

Specified by:
clone in interface Cube
Overrides:
clone in class java.lang.Object

getPartCount

public int getPartCount()
Description copied from interface: Cube
Returns the number of cube parts.

Specified by:
getPartCount in interface Cube

getUnsolvedParts

public int[] getUnsolvedParts()
Returns an array of part ID's, for each part in this cube, which is not at its initial location or has not its initial orientation.

Specified by:
getUnsolvedParts in interface Cube

(c) Werner Randelshofer.
All rights reserved.