forked from clementgallet/FiveStage444
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Analyze.java
162 lines (141 loc) · 4.72 KB
/
Analyze.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package cg.fivestage444;
import cg.fivestage444.Coordinates.Edge5;
import cg.fivestage444.Coordinates.Corner5;
import cg.fivestage444.Coordinates.Center5;
import cg.fivestage444.Stages.Stage4;
import cg.fivestage444.Stages.Stage5;
public final class Analyze {
private static final int N_SIZE5 = Edge5.N_COORD*Corner5.N_COORD*Center5.N_COORD;
private static int length4;
private static long unique;
private static long pos;
private static long done;
private static final byte[] move_list_stage4 = new byte[30];
private static final byte[] allPos5 = new byte[N_SIZE5>>>3];
private static final byte[] allPos5_2 = new byte[N_SIZE5>>>3];
public static void main(String[] args){
Tools.init();
distTable5in4(0);
}
private static void distTable5in4(int coset){
System.out.println("Start analysing coset "+coset);
Stage4 s = new Stage4();
//s.set( coset );
CubeState cube = new CubeState();
cube.init();
CubePack cp = new CubePack();
cp.pack(cube);
int cubeDist;
cubeDist = s.pruning();
done = 0;
for (length4 = 0; length4 < 19; ++length4) {
unique = 0;
pos = 0;
//move_stage5();
/* Copy from allPos5_2 to allPos5 */
for( int idx=0; idx<N_SIZE5>>>3; idx++ )
allPos5[idx] |= allPos5_2[idx];
//if(length4==0)
search_stage4 (s, cp, length4, 0, Moves.N_STAGE_MOVES);
/* Copy from allPos5 to allPos5_2 */
for( int idx=0; idx<N_SIZE5>>>3; idx++ )
allPos5_2[idx] |= allPos5[idx];
System.out.println(String.format("%2d%12d%10d", length4, pos, unique));
}
}
private static void search_stage4(Stage4 s, CubePack cp, int depth, int moves_done, int last_move){
int mov_idx, j;
if (depth == 0 && s.isSolved() ){
save_stage5 (cp);
return;
}
Stage4 t = new Stage4();
CubePack cp2 = new CubePack();
long mask = Moves.moves_mask[last_move];
for (int move = 0; mask != 0 && move < Stage4.N_MOVES; move++, mask >>>= 1) {
if (( mask & 1 ) == 0)
continue;
s.moveTo( move, t );
int dist4 = t.pruning();
if (dist4 > depth-1) continue;
if( ( (depth-1)!=dist4 ) && (depth+dist4<6) ) continue;
cp.moveTo( move, cp2 );
move_list_stage4[moves_done] = (byte)move;
search_stage4 (t, cp2, depth - 1, moves_done + 1, move);
}
}
private static void save_stage5(CubePack cp){
int i;
Stage5 s = new Stage5();
cp.toStage5( s );
s.center.coord = s.center.conjugate(s.edge.sym);
s.corner.coord = s.corner.conjugate(s.edge.sym);
s.edge.sym = 0;
long idx = ((long)s.edge.coord * Corner5.N_COORD + s.corner.coord) * Center5.N_COORD + s.center.coord;
if(( allPos5[(int)(idx>>>3)] >>> (int)(idx & 0x7) & 1 ) == 0 ){
unique++;
int nsym = 1;
allPos5[(int)(idx>>>3)] |= 1 << (idx & 0x7);
done++;
for (int j=0; j<4; j++) {
long symS = Edge5.hasSym[s.edge.coord][j];
for (int k=0; symS != 0; symS>>=1, k++) {
if ((symS & 0x1L) == 0) continue;
long idxx = ((long)s.edge.coord * Corner5.N_COORD + s.corner.conjugate((k<<2)+j)) * Center5.N_COORD + s.center.conjugate((k<<2)+j);
if(( allPos5[(int)(idxx>>>3)] >>> (int)(idxx & 0x7) & 1 ) == 0 ){
allPos5[(int)(idxx>>>3)] |= 1 << (idxx & 0x7);
done++;
}
if (idxx == idx)
nsym++;
}
}
pos += 192/nsym;
}
}
public static void move_stage5 (){
int i;
Stage5 s1 = new Stage5();
Stage5 s2 = new Stage5();
for( long idx=0; idx<N_SIZE5;){
int val = allPos5[(int)(idx>>>3)];
if( val == 0){
idx += 8;
continue;
}
for (long end=Math.min(idx+8, N_SIZE5); idx<end; idx++, val>>=1){
if ((val&1) == 0) continue;
s1.center.coord = (int)(idx % Center5.N_COORD);
s1.edge.coord = (int)(idx / (Corner5.N_COORD*Center5.N_COORD));
s1.corner.coord = (int)(( idx / Center5.N_COORD ) % Corner5.N_COORD);
for (int m=0; m<Stage5.N_MOVES; m++){
s1.moveTo( m, s2 );
s2.center.coord = s2.center.conjugate(s2.edge.sym);
s2.corner.coord = s2.corner.conjugate(s2.edge.sym);
s2.edge.sym = 0;
long idxx = ((long)s2.edge.coord*Corner5.N_COORD+s2.corner.coord)*Center5.N_COORD+s2.center.coord;
if(( allPos5_2[(int)(idxx>>>3)] >>> (int)(idxx & 0x7L) & 1 ) == 0 ){
unique++;
done++;
int nsym = 1;
allPos5_2[(int)(idxx>>>3)] |= 1 << (idxx & 0x7L);
for (int j=0; j<4; j++) {
long symS = Edge5.hasSym[s2.edge.coord][j];
for (int k=0; symS != 0; symS>>=1, k++) {
if ((symS & 0x1L) == 0) continue;
long idxxx = ((long)s2.edge.coord*Corner5.N_COORD+s2.corner.conjugate((k<<2)+j))*Center5.N_COORD+s2.center.conjugate((k<<2)+j);
if(( allPos5_2[(int)(idxxx>>>3)] >>> (int)(idxxx & 0x7) & 1 ) == 0 ){
allPos5_2[(int)(idxxx>>>3)] |= 1 << (idxxx & 0x7);
done++;
}
if( idxxx == idxx)
nsym++;
}
}
pos += 192/nsym;
}
}
}
}
}
}