|
CubeTwister 2.0alpha141 2011-10-13 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectch.randelshofer.rubik.AbstractCube
public abstract class AbstractCube
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:
| 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 |
|---|
public static final int CORNER_PART
public static final int EDGE_PART
public static final int SIDE_PART
public static final int CENTER_PART
public static final int NUMBER_OF_CORNER_PARTS
protected int layerCount
protected int[] cornerLoc
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].
protected int[] cornerOrient
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.
protected int[] edgeLoc
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].
protected int[] edgeOrient
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.
protected int[] sideLoc
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].
protected int[] sideOrient
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.
protected AbstractCube.TransformType transformType
protected int transformAxis
protected int transformAngle
protected int transformMask
protected static final int[][] CORNER_TO_FACE_MAP
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.
protected static final int[] EDGE_TO_AXIS_MAP
The index represents the ID of an edge. The values represent the 3 axes 0=x, 1=y and 2=z.
protected static final int[][] EDGE_TO_ANGLE_MAP
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.
protected static final int[][] EDGE_TO_FACE_MAP
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.
protected int[][] CENTER_TO_SIDE_MAP
The index for the first dimension represents the location, the index for the second dimension the orientation. The values represent the 6 sides.
protected static final int[][][][] CORNER_SWIPE_TABLE
| Constructor Detail |
|---|
public AbstractCube()
public AbstractCube(int layerCount)
layerCount - number of layers on the x, y and z axis.
java.lang.IllegalArgumentException - if the layour count is smaller than 2.| Method Detail |
|---|
public boolean equals(java.lang.Object o)
equals in interface Cubeequals in class java.lang.ObjectCube.hashCode()public int hashCode()
hashCode in interface CubehashCode in class java.lang.ObjectCube.equals(java.lang.Object)public void reset()
reset in interface CubeCube.isSolved()public boolean isSolved()
isSolved in interface Cubepublic void addCubeListener(CubeListener l)
addCubeListener in interface Cubepublic void removeCubeListener(CubeListener l)
removeCubeListener in interface Cubeprotected void fireCubeTwisted(CubeEvent event)
protected void fireCubeChanged(CubeEvent event)
public void setQuiet(boolean b)
setQuiet in interface Cubepublic boolean isQuiet()
public int[] getCornerLocations()
getCornerLocations in interface Cubepublic int[] getCornerOrientations()
getCornerOrientations in interface Cube
public void setCorners(int[] locations,
int[] orientations)
setCorners in interface Cubelocations - 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().public int getCornerAt(int location)
getCornerAt in interface Cubepublic int getCornerLocation(int corner)
getCornerLocation in interface Cubepublic int getCornerCount()
getCornerCount in interface Cubepublic int getEdgeCount()
getEdgeCount in interface Cubepublic int getSideCount()
getSideCount in interface Cubepublic int getCornerOrientation(int corner)
getCornerOrientation in interface Cubepublic int[] getEdgeLocations()
getEdgeLocations in interface Cubepublic int[] getEdgeOrientations()
getEdgeOrientations in interface Cube
public void setEdges(int[] locations,
int[] orientations)
setEdges in interface Cubelocations - 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().public int getEdgeAt(int location)
getEdgeAt in interface Cubepublic int getEdgeLocation(int edge)
getEdgeLocation in interface Cubepublic int getEdgeOrientation(int edge)
getEdgeOrientation in interface Cubepublic int[] getSideLocations()
getSideLocations in interface Cubepublic int[] getSideOrientations()
getSideOrientations in interface Cube
public void setSides(int[] locations,
int[] orientations)
setSides in interface Cubelocations - 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().public int getSideAt(int location)
getSideAt in interface Cubepublic int getSideLocation(int side)
getSideLocation in interface Cubepublic int getSideOrientation(int side)
getSideOrientation in interface Cubepublic void setTo(Cube tx)
setTo in interface Cubetx - The cube to be applied to this cube object.public int getLayerCount()
getLayerCount in interface Cube
public final void transform(int axis,
int layerMask,
int angle)
transform in interface Cubeaxis - 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;angle - positive values=clockwise rotationgetLayerCount()
protected abstract void transform0(int axis,
int layerMask,
int angle)
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;angle - positive values=clockwise rotationgetLayerCount()public void transform(Cube tx)
transform in interface Cubetx - The cube to be used to transform this cube object.
InvalidArgumentException, - if one or more of the values returned
by tx.getLayourCount(axis) are different from this cube.getLayerCount()
protected void twoCycle(int[] loc,
int l1,
int l2,
int[] orient,
int o1,
int o2,
int modulo)
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)
public int getPartFace(int part,
int orient)
getPartFace in interface Cubepublic int getPartOrientation(int part)
getPartOrientation in interface Cubepublic int getPartLocation(int part)
getPartLocation in interface Cube
public int getPartAxis(int part,
int orientation)
getPartAxis in interface Cube
public int getPartAngle(int part,
int orientation)
getPartAngle in interface Cube
public abstract int getPartLayerMask(int part,
int orientation)
getPartLayerMask in interface Cubepublic int getPartType(int part)
getPartType in interface Cubepublic int getPartAt(int location)
getPartAt in interface Cubepublic int getCubeOrientation()
getCubeOrientation in interface Cubepublic java.lang.Object clone()
Cube
clone in interface Cubeclone in class java.lang.Objectpublic int getPartCount()
Cube
getPartCount in interface Cubepublic int[] getUnsolvedParts()
getUnsolvedParts in interface Cube
|
(c) Werner Randelshofer. All rights reserved. |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||