if ((testValue & 0x08) != 0) {
System.out.println(String.format("Initialization Time: %d ms\r", System.nanoTime() - tm));
}
Search search = new Search();
String sol;
if ((testValue & 0x10) != 0) {
System.out.println("========== Selected Scramble Solving Test (Optimal Solver) ==========");
System.out.print("IdCube Test: \"");
String scr = Tools.fromScramble(new int[0]);
System.out.print(search.solution(scr, 21, 100000, 0, Search.OPTIMAL_SOLUTION));
System.out.println("\"");
int n_test = 0;
long curTime;
for (int length = 1; length < 5; length++) {
System.out.print(String.format("%d-Move: ", length));
curTime = System.nanoTime();
n_test = testOptimal(length, 0, new int[length], -1, search, Search.OPTIMAL_SOLUTION);
System.out.println(String.format("OK, All %d Cube(s) Solved Optimally. AvgTime: %1.3f ms.", n_test, (System.nanoTime() - curTime) / 1000000d / n_test));
}
for (int length = 5; length < 15; length++) {
System.out.print(String.format("%d-Move: ", length));
Random gen = new Random(42L);
curTime = System.nanoTime();
n_test = 0;
while (System.nanoTime() - curTime < 1e9) {
testRandomOptimal(length, search, gen, Search.OPTIMAL_SOLUTION);
++n_test;
}
System.out.println(String.format("OK, %d Cube(s) Solved Optimally. AvgTime: %1.3f ms.", n_test, (System.nanoTime() - curTime) / 1000000d / n_test));
}
System.out.println("========== Selected Scramble Solving Test (Two-phase Solver) ==========");
System.out.print("IdCube Test: \"");
scr = Tools.fromScramble(new int[0]);
System.out.print(search.solution(scr, 21, 100000, 0, Search.OPTIMAL_SOLUTION));
System.out.println("\"");
for (int length = 1; length < 5; length++) {
System.out.print(String.format("%d-Move: ", length));
curTime = System.nanoTime();
n_test = testOptimal(length, 0, new int[length], -1, search, 0);
System.out.println(String.format("OK, All %d Cube(s) Solved Optimally. AvgTime: %1.3f ms.", n_test, (System.nanoTime() - curTime) / 1000000d / n_test));
}
for (int length = 5; length < 15; length++) {
System.out.print(String.format("%d-Move: ", length));
Random gen = new Random(42L);
curTime = System.nanoTime();
n_test = 0;
while (System.nanoTime() - curTime < 1e9) {
testRandomOptimal(length, search, gen, 0);
++n_test;
}
System.out.println(String.format("OK, %d Cube(s) Solved Optimally. AvgTime: %1.3f ms.", n_test, (System.nanoTime() - curTime) / 1000000d / n_test));
}
System.out.print("SuperFlip: ");
curTime = System.nanoTime();
sol = search.solution(Tools.superFlip(), 20, 100000, 0, 0);
while (sol.length() > 60 || sol.startsWith("Error")) {
if (sol.startsWith("Error") && !sol.startsWith("Error 8")) {
throw new RuntimeException(String.format("Cannot find the optimal solution: %s", sol));
}
sol = search.next(100000, 0, 0);
}
System.out.println(String.format("OK. Time: %1.3f ms.", (System.nanoTime() - curTime) / 1000000d));
System.out.print("20-Depth: ");
String[] depth20 = new String[] {
"B2 L B2 R' F' U' B' L D' F' L U L2 B2 L' D2 B2 D2 R2 B2",
"R U2 R D2 R2 B2 L' D' B' F U B' R' U2 L' D R2 F' U2 L2",
"D2 R2 F2 D2 F2 D2 R' F2 D' L2 R B L' F U R' B F2 R2 F'",
"D' F' U B2 R2 F R' U2 B' L D F R D2 R2 L2 D' R2 F2 D'",
"U2 R2 F2 D' U F2 U2 B U B' R U' F L B R' F L2 D' B ",
"D B2 D' B2 R2 D' R2 U L R' D B' D R F' D2 R2 U' F' R ",
"B D' L' F' L F B U' D2 F' R2 B' U F2 R' L U2 R2 F2 B2",
"U2 L' U2 F2 L' R D2 L2 B' D2 L F' R' U' L U2 F' D' R B ",
"F' L B2 R U' B' L U2 D' F L' R2 U2 D2 B2 R2 D R2 L2 F2",
"U2 R2 D2 B U2 B' F D' B' R' D U2 B2 F2 R' D' B U' F' R2"
};
n_test = 10;
curTime = System.nanoTime();
for (int i = 0; i < depth20.length; i++) {
sol = search.solution(Tools.fromScramble(depth20[0]), 20, 100000, 0, 0);
}
System.out.println(String.format("OK, Random %d Cube(s) Solved. AvgTime: %1.3f ms.", n_test, (System.nanoTime() - curTime) / 1000000d / n_test));
}
if ((testValue & 0x20) != 0) {
System.out.println("========== Random Scramble Solving Test (Two-phase Solver) ==========");
System.out.println(String.format("Solve Random %d Cubes:", nSolves));
System.out.println(
"MaxLength: " + maxLength + "\n" +
"ProbeMax: " + probeMax + "\n" +
"ProbeMin: " + probeMin + "\n" +
"verbose: " + verbose);
tm = System.nanoTime();
int total = 0;
int x = 0;
// System.out.print("Average Solving Time: - nanoSecond(s)\r");
long minT = 1L << 62;
long maxT = 0L;
long totalTime = 0;
Tools.setRandomSource(new Random(42L));
int totalLength = 0;
while (System.nanoTime() - tm < 60000000000L && x < nSolves) {
long curTime = System.nanoTime();
String cube = Tools.randomCube();
String s = search.solution(cube, maxLength, probeMax, probeMin, verbose);
if (s.length() > 63) {
s = search.next(probeMax, 0, verbose);
}
curTime = System.nanoTime() - curTime;
totalTime += curTime;
maxT = Math.max(maxT, curTime);
minT = Math.min(minT, curTime);