-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSearchTest.java
67 lines (61 loc) · 2.27 KB
/
SearchTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cs.sq12phase;
public class SearchTest {
static void OptimalSolverTest() {
long t = System.nanoTime();
Search s = new Search();
java.util.Random gen = new java.util.Random(42L);
int targetLength = 11;
int scrambleLength = 11;
for (int x = 0; x < 1000; x++) {
FullCube fc = new FullCube();
int shape = fc.getShapeIdx();
int lm = -1;
for (int i = 0; i < scrambleLength; i++) {
int move;
do {
move = gen.nextInt(3);
} while (move == lm || move == 1 && lm == 2);
lm = move;
if (move == 0) {
s.move[i] = 0;
fc.doMove(0);
} else if (move == 1) {
int m = Shape.TopMove[shape] & 0xf;
s.move[i] = m;
fc.doMove(m);
} else {
int m = Shape.BottomMove[shape] & 0xf;
s.move[i] = -m;
fc.doMove(-m);
}
shape = fc.getShapeIdx();
}
s.verbose = 0;
System.out.println("Scramble: " + s.move2string(scrambleLength));
String sol = s.solutionOpt(fc, targetLength);
System.out.println("Solution: " + sol);
System.out.println(
String.format("%.2fms\n",
(System.nanoTime() - t) / 1000000.0 / (x + 1)));
}
}
static void RandomSolvingTest() {
long t = System.nanoTime();
Search s = new Search();
java.util.Random gen = new java.util.Random(42L);
for (int x = 0; x < 1000; x++) {
String sol = s.solution(FullCube.randomCube(gen), Search.INVERSE_SOLUTION);
System.out.println(sol);
System.out.println(
String.format("%.2fms",
(System.nanoTime() - t) / 1000000.0 / (x + 1)));
}
}
public static void main(String[] args) {
long t = System.nanoTime();
new Search().solution(new FullCube(""));
System.out.println((System.nanoTime() - t) / 1e9 + " seconds to initialize");
RandomSolvingTest();
OptimalSolverTest();
}
}