public class TwoPhase extends Object
Modifier and Type | Field and Description |
---|---|
(package private) static int[] |
ax
The axis of the move (U,R,F,D,L,B)
|
(package private) static int[] |
flip
corners orientation coordinates
|
(package private) static int[] |
FRtoBR |
(package private) static int[] |
minDistPhase1 |
(package private) static int[] |
minDistPhase2 |
(package private) static int[] |
parity |
(package private) static int[] |
po
The power of the move (90, 180 or -90 degrees)
|
(package private) static int[] |
slice
UD slice coordinates (phase 1)
|
private static String |
SOVED_CUBE |
(package private) static int[] |
twist
edges orientation coordinates
|
(package private) static int[] |
UBtoDF |
(package private) static int[] |
URFtoDLF |
(package private) static int[] |
URtoDF |
(package private) static int[] |
URtoUL |
Constructor and Description |
---|
TwoPhase() |
Modifier and Type | Method and Description |
---|---|
private static void |
createMovesList(List<Move> moves,
int depth)
Creates the list of moves that was found for solving the cube
|
static int |
findSolution(String cube,
int maxDepth,
long timeOut,
List<Move> moves)
Finds list of moves for solving received cube with no more than @maxDepth moves.
|
static int |
findSolution(String cube,
int maxDepth,
long timeOut,
List<Move> moves,
String pattern)
Finds list of moves for solving received cube with no more than @maxDepth moves.
|
private static int |
totalDepth(int depthPhase1,
int maxDepth)
Apply phase2 of algorithm and return the combined phase1 and phase2 depth.
|
private static int |
validateCubeString(String cube,
CubieCube cubieCube)
Validates input cube string and returns a corresponding error code.
|
static int[] ax
static int[] po
static int[] flip
static int[] twist
static int[] slice
static int[] parity
static int[] URFtoDLF
static int[] FRtoBR
static int[] URtoDF
static int[] URtoUL
static int[] UBtoDF
static int[] minDistPhase1
static int[] minDistPhase2
private static final String SOVED_CUBE
public static int findSolution(String cube, int maxDepth, long timeOut, List<Move> moves, String pattern)
cube
- - the cube definition string.
The format is a 54 long string containing the characters U, R, F, D, L and B
where each char corresponds to the color of a facelet.
Faceletes colors should appear in the following order:
U1 U2 ... U9 R1 R2 ... R9 F1 F2 ... F9 D1 D2 ... D9 L1 L2 ... L9 B1 B2 ... B9
see Facelet
for more info about the format.maxDepth
- - defines the maximal allowed maneuver length. For random cubes, a maxDepth of 21 usually will return a
solution in less than 0.5 seconds. With a maxDepth of 20 it takes a few seconds on average to find a
solution, but it may take much longer for specific cubes.timeOut
- - defines the maximum computing time of the method in seconds. If it does not return with a solution, it returns with
an error code.moves
- - a list to contain suggested solution moves. If a solution was found, the list is cleared before adding the required
moves to it. Otherwise, the list remains the same.pattern
- - the desired pattern definition string.
The returned list of moves can bring entered cube to this pattern (and not to the standard solved cube).
The format should be like cube's foramt.public static int findSolution(String cube, int maxDepth, long timeOut, List<Move> moves)
cube
- - the cube definition string.
The format is a 54 long string containing the characters U, R, F, D, L and B
where each char corresponds to the color of a facelet.
Faceletes colors should appear in the following order:
U1 U2 ... U9 R1 R2 ... R9 F1 F2 ... F9 D1 D2 ... D9 L1 L2 ... L9 B1 B2 ... B9
see Facelet
for more info about the format.maxDepth
- - defines the maximal allowed maneuver length. For random cubes, a maxDepth of 21 usually will return a
solution in less than 0.5 seconds. With a maxDepth of 20 it takes a few seconds on average to find a
solution, but it may take much longer for specific cubes.timeOut
- - defines the maximum computing time of the method in seconds. If it does not return with a solution, it returns with
an error code.moves
- - a list to contain suggested solution moves. If a solution was found, the list is cleared before adding the required
moves to it. Otherwise, the list remains the same.private static int validateCubeString(String cube, CubieCube cubieCube)
cube
- - the cube string to validatecubieCube
- - cubie representation of the cube represented by the string (valid only when string is valid)private static void createMovesList(List<Move> moves, int depth)
moves
- - the list to contain the moves for solving the cubedepth
- - the depth of the solution that was found (number of moves)private static int totalDepth(int depthPhase1, int maxDepth)
depthPhase1
- is the maneuver length phase1 that led to this phase2 searchmaxDepth
- defines the maximal allowed maneuver length