1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2021 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.objectlib.scrambling;
|
11
|
|
12
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
13
|
|
14
|
public class ScrambleEdgeGenerator
|
15
|
{
|
16
|
private static void insertSection(int[] table, int startIndex, int size, int startAlg, int state)
|
17
|
{
|
18
|
int num = size/2;
|
19
|
|
20
|
for(int i=0; i<num; i++)
|
21
|
{
|
22
|
table[2*(i+startIndex) ] = startAlg +i;
|
23
|
table[2*(i+startIndex)+1] = state;
|
24
|
}
|
25
|
}
|
26
|
|
27
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28
|
|
29
|
private static int[] createEdgeCuboid(int sizeX, int sizeY, int sizeZ, int stateX, int stateY, int stateZ)
|
30
|
{
|
31
|
int num = 0;
|
32
|
int consX = ( ((sizeY-sizeZ)%2)!=0 ? 2:6 ) * sizeX;
|
33
|
int consY = ( ((sizeX-sizeZ)%2)!=0 ? 2:6 ) * sizeY;
|
34
|
int consZ = ( ((sizeX-sizeY)%2)!=0 ? 2:6 ) * sizeZ;
|
35
|
if( stateX>=0 ) num += consX;
|
36
|
if( stateY>=0 ) num += consY;
|
37
|
if( stateZ>=0 ) num += consZ;
|
38
|
|
39
|
int[] ret = new int[num];
|
40
|
int index = 0;
|
41
|
int algor = 0;
|
42
|
if( stateX>=0 ) { insertSection(ret,index,consX,algor,stateX); index += consX/2; }
|
43
|
algor += consX/2;
|
44
|
if( stateY>=0 ) { insertSection(ret,index,consY,algor,stateY); index += consY/2; }
|
45
|
algor += consY/2;
|
46
|
if( stateZ>=0 ) { insertSection(ret,index,consZ,algor,stateZ); }
|
47
|
|
48
|
return ret;
|
49
|
}
|
50
|
|
51
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
52
|
|
53
|
public static int[][] getScrambleEdgesCuboid(int X, int Y, int Z)
|
54
|
{
|
55
|
return new int[][]
|
56
|
{
|
57
|
createEdgeCuboid(X,Y,Z, 1, 2, 3), // 0 0
|
58
|
createEdgeCuboid(X,Y,Z,-1, 4, 5), // 1 x
|
59
|
createEdgeCuboid(X,Y,Z, 6,-1, 7), // 2 y
|
60
|
createEdgeCuboid(X,Y,Z, 8, 9,-1), // 3 z
|
61
|
createEdgeCuboid(X,Y,Z,10,-1, 7), // 4 xy
|
62
|
createEdgeCuboid(X,Y,Z,11, 9,-1), // 5 xz
|
63
|
createEdgeCuboid(X,Y,Z,-1,12, 5), // 6 yx
|
64
|
createEdgeCuboid(X,Y,Z, 8,13,-1), // 7 yz
|
65
|
createEdgeCuboid(X,Y,Z,-1, 4,14), // 8 zx
|
66
|
createEdgeCuboid(X,Y,Z, 6,-1,15), // 9 zy
|
67
|
createEdgeCuboid(X,Y,Z,-1,-1, 5), // 10 xyx
|
68
|
createEdgeCuboid(X,Y,Z,-1, 4,-1), // 11 xzx
|
69
|
createEdgeCuboid(X,Y,Z,-1,-1, 7), // 12 yxy
|
70
|
createEdgeCuboid(X,Y,Z, 6,-1,-1), // 13 yzy
|
71
|
createEdgeCuboid(X,Y,Z,-1, 9,-1), // 14 zxz
|
72
|
createEdgeCuboid(X,Y,Z, 8,-1,-1), // 15 zyz
|
73
|
};
|
74
|
}
|
75
|
|
76
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77
|
|
78
|
public static int[][] getScrambleEdgesSingle(int[][] basicAngle)
|
79
|
{
|
80
|
int size=0;
|
81
|
|
82
|
for (int[] basic : basicAngle)
|
83
|
for (int i : basic) size += (i-1);
|
84
|
|
85
|
int[] edge = new int[2*size];
|
86
|
for(int i=0; i<size; i++)
|
87
|
{
|
88
|
edge[2*i ] = i;
|
89
|
edge[2*i+1] = 0;
|
90
|
}
|
91
|
|
92
|
return new int[][] { edge };
|
93
|
}
|
94
|
|
95
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96
|
|
97
|
public static int[][] getScrambleEdgesSingle(int[][] basicAngles, boolean[][] rotatable)
|
98
|
{
|
99
|
int num=0;
|
100
|
int numAxis= basicAngles.length;
|
101
|
|
102
|
for(int a=0; a<numAxis; a++)
|
103
|
{
|
104
|
int[] angles = basicAngles[a];
|
105
|
int numLayers = angles.length;
|
106
|
|
107
|
for(int l=0; l<numLayers; l++)
|
108
|
if( rotatable[a][l] )
|
109
|
num += (angles[l]-1);
|
110
|
}
|
111
|
|
112
|
int[] edge = new int[2*num];
|
113
|
for(int i=0; i<num; i++)
|
114
|
{
|
115
|
edge[2*i ] = i;
|
116
|
edge[2*i+1] = 0;
|
117
|
}
|
118
|
|
119
|
return new int[][] { edge };
|
120
|
}
|
121
|
|
122
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123
|
|
124
|
public static int[][] getScramblingAlgorithms(int[][] basicAngles)
|
125
|
{
|
126
|
int numAxis= basicAngles.length;
|
127
|
int num=0;
|
128
|
|
129
|
for (int[] basic : basicAngles)
|
130
|
for (int i : basic) num += (i-1);
|
131
|
|
132
|
int[][] ret = new int[num][3];
|
133
|
int index = 0;
|
134
|
|
135
|
for(int a=0; a<numAxis; a++)
|
136
|
{
|
137
|
int numLayers = basicAngles[a].length;
|
138
|
|
139
|
for(int l=0; l<numLayers; l++)
|
140
|
{
|
141
|
int N = basicAngles[a][l];
|
142
|
int NEG = (1-N)/2;
|
143
|
int POS = N/2;
|
144
|
int layerBmp = (1<<l);
|
145
|
|
146
|
for(int k=NEG; k<=-1; k++)
|
147
|
{
|
148
|
ret[index][0] = a;
|
149
|
ret[index][1] = layerBmp;
|
150
|
ret[index][2] = k;
|
151
|
index++;
|
152
|
}
|
153
|
|
154
|
for(int k=1; k<=POS; k++)
|
155
|
{
|
156
|
ret[index][0] = a;
|
157
|
ret[index][1] = layerBmp;
|
158
|
ret[index][2] = k;
|
159
|
index++;
|
160
|
}
|
161
|
}
|
162
|
}
|
163
|
|
164
|
return ret;
|
165
|
}
|
166
|
|
167
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
168
|
|
169
|
public static int[][] getScramblingAlgorithms(int[][] basicAngles, boolean[][] rotatable)
|
170
|
{
|
171
|
int numAxis= basicAngles.length;
|
172
|
int num=0;
|
173
|
|
174
|
for(int a=0; a<numAxis; a++)
|
175
|
{
|
176
|
int[] angles = basicAngles[a];
|
177
|
int numLayers = angles.length;
|
178
|
|
179
|
for(int l=0; l<numLayers; l++)
|
180
|
if( rotatable[a][l] )
|
181
|
num += (angles[l]-1);
|
182
|
}
|
183
|
|
184
|
int[][] ret = new int[num][3];
|
185
|
int index = 0;
|
186
|
|
187
|
for(int a=0; a<numAxis; a++)
|
188
|
{
|
189
|
int numLayers = basicAngles[a].length;
|
190
|
|
191
|
for(int l=0; l<numLayers; l++)
|
192
|
{
|
193
|
if( rotatable[a][l] )
|
194
|
{
|
195
|
int N = basicAngles[a][l];
|
196
|
int NEG = (1-N)/2;
|
197
|
int POS = N/2;
|
198
|
int layerBmp = (1<<l);
|
199
|
|
200
|
for(int k=NEG; k<=-1; k++)
|
201
|
{
|
202
|
ret[index][0] = a;
|
203
|
ret[index][1] = layerBmp;
|
204
|
ret[index][2] = k;
|
205
|
index++;
|
206
|
}
|
207
|
|
208
|
for(int k=1; k<=POS; k++)
|
209
|
{
|
210
|
ret[index][0] = a;
|
211
|
ret[index][1] = layerBmp;
|
212
|
ret[index][2] = k;
|
213
|
index++;
|
214
|
}
|
215
|
}
|
216
|
}
|
217
|
}
|
218
|
|
219
|
return ret;
|
220
|
}
|
221
|
}
|
222
|
|