MCPcopy Create free account
hub / github.com/MeigenChou/DCTimer-Android / init

Method init

app/src/main/java/cs/sq12phase/Square.java:22–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20 static boolean ini = false;
21
22 public static void init() {
23 if (ini) {
24 return;
25 }
26 int[] pos = new int[8];
27 int temp;
28
29 for (int i = 0; i < 40320; i++) {
30 //twist
31 Utils.set8Perm(pos, 8, i);
32
33 temp = pos[2]; pos[2] = pos[4]; pos[4] = temp;
34 temp = pos[3]; pos[3] = pos[5]; pos[5] = temp;
35 sqTwistMove[i] = (char) Utils.get8Perm(pos, 8);
36
37 //top layer turn
38 Utils.set8Perm(pos, 8, i);
39 temp = pos[0]; pos[0] = pos[1]; pos[1] = pos[2]; pos[2] = pos[3]; pos[3] = temp;
40 sqTopMove[i] = (char) Utils.get8Perm(pos, 8);
41
42 //bottom layer turn
43 Utils.set8Perm(pos, 8, i);
44 temp = pos[4]; pos[4] = pos[5]; pos[5] = pos[6]; pos[6] = pos[7]; pos[7] = temp;
45 sqBottomMove[i] = (char) Utils.get8Perm(pos, 8);
46 }
47
48 for (int i = 0; i < 40320 * 2; i++) {
49 SquarePrun[i] = -1;
50 }
51 SquarePrun[0] = 0;
52 int depth = 0;
53 int done = 1;
54 while (done < 40320 * 2) {
55 boolean inv = depth >= 11;
56 int find = inv ? -1 : depth;
57 int check = inv ? depth : -1;
58 ++depth;
59 OUT:
60 for (int i = 0; i < 40320 * 2; i++) {
61 if (SquarePrun[i] != find) {
62 continue;
63 }
64 int perm = i >> 1;
65 int ml = i & 1;
66
67 //try twist
68 int idx = sqTwistMove[perm] << 1 | (1 - ml);
69 if (SquarePrun[idx] == check) {
70 ++done;
71 SquarePrun[inv ? i : idx] = (byte) (depth);
72 if (inv) continue;
73 }
74
75 //try turning top layer
76 for (int m = 0; m < 4; m++) {
77 perm = sqTopMove[perm];
78 idx = perm << 1 | ml;
79 if (SquarePrun[idx] == check) {

Callers 1

SearchClass · 0.95

Calls 2

set8PermMethod · 0.95
get8PermMethod · 0.95

Tested by

no test coverage detected