1 |
e9bff328
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2023 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.tablebases;
|
11 |
|
|
|
12 |
|
|
import static org.distorted.objectlib.main.TwistyObject.SQ3;
|
13 |
|
|
|
14 |
|
|
import org.distorted.library.type.Static3D;
|
15 |
|
|
import org.distorted.objectlib.R;
|
16 |
3103c3c8
|
Leszek Koltunski
|
import org.distorted.objectlib.helpers.OperatingSystemInterface;
|
17 |
e9bff328
|
Leszek Koltunski
|
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
dbcd5ff2
|
Leszek Koltunski
|
public class TBSkewb extends TablebasesPruning
|
21 |
e9bff328
|
Leszek Koltunski
|
{
|
22 |
8a489ebd
|
Leszek Koltunski
|
public static final int[] FIXED= {0,3,5,6};
|
23 |
|
|
public static final int[] FREE = {1,2,4,7};
|
24 |
|
|
|
25 |
2d697abd
|
Leszek Koltunski
|
private static final int[][] freeIndex = { {1,3,2},{0,2,3},{3,1,0},{2,0,1} };
|
26 |
|
|
|
27 |
cc7d45d1
|
Leszek Koltunski
|
private static final int[][][] centerQuats =
|
28 |
|
|
{
|
29 |
|
|
{ {0,10},{9,11},{1,7},{4,6},{2,5},{3,8} },
|
30 |
|
|
{ {9,11},{0,10},{4,6},{1,7},{3,8},{2,5} },
|
31 |
|
|
{ {2,8},{3,5},{0,11},{9,10},{1,4},{6,7} },
|
32 |
|
|
{ {3,5},{2,8},{9,10},{0,11},{6,7},{1,4} },
|
33 |
|
|
{ {1,6},{4,7},{2,3},{5,8},{0,9},{10,11} },
|
34 |
|
|
{ {4,7},{1,6},{5,8},{2,3},{10,11},{0,9} }
|
35 |
|
|
};
|
36 |
|
|
|
37 |
|
|
// [1][] are the 3 quats the 1st 'fixed' corner will have when 'fakeTwisted' (which in case of
|
38 |
|
|
// the fixed corners is the same as the final twist) with respectively twist 0,1,2.
|
39 |
|
|
|
40 |
|
|
private static final int[][] fixedQuats = { {0,1,2},{0,7,8},{0,6,5},{0,4,3} };
|
41 |
|
|
|
42 |
|
|
// [1][2][] are the 3 quats the 1st free corner, when permuted to the location of the 2nd corner,
|
43 |
|
|
// will have when it is 'fakeTwisted' with fakeTwist 0,1,2.
|
44 |
|
|
// fakeTwist is an intermediate twist which needs yet to be translated to the final twist of the
|
45 |
|
|
// corners (which needs to sum up to something divisible by 3).
|
46 |
|
|
|
47 |
|
|
private static final int[][][] freeQuats=
|
48 |
|
|
{
|
49 |
|
|
{ {0,3,4},{9,8,1},{6,11,2},{7,10,5} },
|
50 |
|
|
{ {9,2,7},{0,5,6},{1,10,3},{4,11,8} },
|
51 |
|
|
{ {5,1,11},{2,4,10},{0,8,7},{9,3,6} },
|
52 |
|
|
{ {8,6,10},{3,7,11},{9,5,4},{0,2,1} }
|
53 |
|
|
};
|
54 |
|
|
|
55 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56 |
|
|
|
57 |
e9bff328
|
Leszek Koltunski
|
public TBSkewb()
|
58 |
|
|
{
|
59 |
|
|
super();
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63 |
|
|
|
64 |
3103c3c8
|
Leszek Koltunski
|
public TBSkewb(OperatingSystemInterface os)
|
65 |
e9bff328
|
Leszek Koltunski
|
{
|
66 |
3103c3c8
|
Leszek Koltunski
|
super(os,new int[] {R.raw.skew_2_pruning4,R.raw.skew_2_pruning5},new int[]{R.raw.skew_2_pruning11});
|
67 |
e9bff328
|
Leszek Koltunski
|
}
|
68 |
|
|
|
69 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
|
71 |
|
|
int[][] getBasicAngles()
|
72 |
|
|
{
|
73 |
|
|
int[] tmp = {3,3};
|
74 |
|
|
return new int[][] { tmp,tmp,tmp,tmp };
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78 |
|
|
|
79 |
|
|
Static3D[] getRotationAxis()
|
80 |
|
|
{
|
81 |
|
|
return new Static3D[]
|
82 |
|
|
{
|
83 |
|
|
new Static3D( SQ3/3, SQ3/3, SQ3/3),
|
84 |
|
|
new Static3D( SQ3/3, SQ3/3,-SQ3/3),
|
85 |
|
|
new Static3D( SQ3/3,-SQ3/3, SQ3/3),
|
86 |
|
|
new Static3D( SQ3/3,-SQ3/3,-SQ3/3)
|
87 |
|
|
};
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
|
92 |
|
|
float[][] getPosition()
|
93 |
|
|
{
|
94 |
|
|
return new float[][]
|
95 |
|
|
{
|
96 |
|
|
{ 1, 1, 1 },
|
97 |
|
|
{ 1, 1,-1 },
|
98 |
|
|
{ 1,-1, 1 },
|
99 |
|
|
{ 1,-1,-1 },
|
100 |
|
|
{-1, 1, 1 },
|
101 |
|
|
{-1, 1,-1 },
|
102 |
|
|
{-1,-1, 1 },
|
103 |
|
|
{-1,-1,-1 },
|
104 |
|
|
|
105 |
|
|
{ 0, 0, 1 },
|
106 |
|
|
{ 0, 0,-1 },
|
107 |
|
|
{ 0, 1, 0 },
|
108 |
|
|
{ 0,-1, 0 },
|
109 |
|
|
{ 1, 0, 0 },
|
110 |
|
|
{-1, 0, 0 }
|
111 |
|
|
};
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115 |
|
|
|
116 |
|
|
float[][] getCuts()
|
117 |
|
|
{
|
118 |
|
|
float[] cut = {0};
|
119 |
|
|
return new float[][] { cut,cut,cut,cut };
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123 |
|
|
|
124 |
|
|
boolean[][] getRotatable()
|
125 |
|
|
{
|
126 |
|
|
boolean[] t1 = new boolean[] {false,true};
|
127 |
|
|
boolean[] t2 = new boolean[] {true,false};
|
128 |
|
|
return new boolean[][] { t1,t2,t2,t1 };
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132 |
|
|
// specifically for the tablebase
|
133 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
134 |
|
|
|
135 |
|
|
int getSize()
|
136 |
|
|
{
|
137 |
|
|
return 3149280; // see https://www.jaapsch.net/puzzles/skewb.htm
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
141 |
|
|
|
142 |
|
|
int getMinScramble()
|
143 |
|
|
{
|
144 |
|
|
return 9;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
dbcd5ff2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
148 |
|
|
|
149 |
|
|
int[] getMidPruningLevels()
|
150 |
|
|
{
|
151 |
|
|
return new int[] {4,5};
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
155 |
|
|
|
156 |
|
|
int[] getHighPruningLevels()
|
157 |
|
|
{
|
158 |
|
|
return new int[] {11};
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
162 |
|
|
|
163 |
|
|
int getGodsNumber()
|
164 |
|
|
{
|
165 |
|
|
return 11;
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
169 |
|
|
|
170 |
|
|
boolean moveCanProceed(int lastA, int lastR, int currA, int currR)
|
171 |
|
|
{
|
172 |
|
|
return lastA!=currA;
|
173 |
|
|
}
|
174 |
|
|
|
175 |
cc7d45d1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176 |
|
|
|
177 |
2d697abd
|
Leszek Koltunski
|
public static int computeLocation(int index, int quat)
|
178 |
cc7d45d1
|
Leszek Koltunski
|
{
|
179 |
|
|
for(int i=0; i<4; i++)
|
180 |
|
|
{
|
181 |
2d697abd
|
Leszek Koltunski
|
int[] q = freeQuats[index][i];
|
182 |
cc7d45d1
|
Leszek Koltunski
|
if( quat==q[0] || quat==q[1] || quat==q[2] ) return i;
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
android.util.Log.e("D", "error in computeLocation, quat="+quat);
|
186 |
|
|
return -1;
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
190 |
|
|
|
191 |
|
|
private static int retFixed(int index, int quat)
|
192 |
|
|
{
|
193 |
|
|
int[] qs = fixedQuats[index];
|
194 |
|
|
|
195 |
|
|
if( quat==qs[0]) return 0;
|
196 |
|
|
if( quat==qs[1]) return 1;
|
197 |
|
|
if( quat==qs[2]) return 2;
|
198 |
|
|
|
199 |
|
|
android.util.Log.e("D", "error in retFixed, index="+index+" quat="+quat);
|
200 |
|
|
return -1;
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
204 |
|
|
|
205 |
|
|
private static int retFree(int index, int quat)
|
206 |
|
|
{
|
207 |
|
|
int[][] qs = freeQuats[index];
|
208 |
|
|
|
209 |
|
|
for(int i=0; i<4; i++)
|
210 |
|
|
{
|
211 |
|
|
if( quat==qs[i][0]) return 0;
|
212 |
|
|
if( quat==qs[i][1]) return 1;
|
213 |
|
|
if( quat==qs[i][2]) return 2;
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
android.util.Log.e("D", "error in retFree, index="+index+" quat="+quat);
|
217 |
|
|
return -1;
|
218 |
|
|
}
|
219 |
|
|
|
220 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
221 |
|
|
// In case of the four 'fixed' corners (0,3,5,6) which do not change their location,
|
222 |
|
|
// the twist is natural: 0 in the init positions and increasing 1 mod 3 on each CW turn.
|
223 |
|
|
//
|
224 |
|
|
// In case of the four 'free' corners their twist is relative to the position of the 'free'
|
225 |
|
|
// tetrahedron. And so, for example the twist of free corner 1 (whose 0th face is orange) is equal
|
226 |
|
|
// to 0 if free corner 7 is on the same face like 0th face of corner 1 (which is the case in init
|
227 |
|
|
// position); then once free corners 2,4,7 permute CW, twist of corner 1 increases by 1 mod 3.
|
228 |
|
|
|
229 |
|
|
public static void computeCornerTwists(int[] twists, int[] quats)
|
230 |
|
|
{
|
231 |
8a489ebd
|
Leszek Koltunski
|
for(int i=0; i<4; i++) twists[FIXED[i]] = retFixed(i,quats[FIXED[i]]);
|
232 |
|
|
for(int i=0; i<4; i++) twists[FREE[i]] = retFree(i,quats[FREE[i]]);
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
236 |
|
|
|
237 |
|
|
public static void fillInQuats(int[] quats, int[] perm, int[] twist)
|
238 |
|
|
{
|
239 |
|
|
for(int i=0; i<4; i++)
|
240 |
|
|
{
|
241 |
|
|
int fixed = FIXED[i];
|
242 |
|
|
int free = FREE[i];
|
243 |
|
|
int twFi = twist[fixed];
|
244 |
|
|
int twFr = twist[free];
|
245 |
|
|
int pe = perm[i];
|
246 |
|
|
|
247 |
|
|
quats[fixed] = fixedQuats[i][twFi];
|
248 |
|
|
quats[free ] = freeQuats[i][pe][twFr];
|
249 |
|
|
}
|
250 |
cc7d45d1
|
Leszek Koltunski
|
}
|
251 |
|
|
|
252 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
253 |
|
|
|
254 |
|
|
private int[] computeCenterPerm(int[] quats)
|
255 |
|
|
{
|
256 |
|
|
int[] output = new int[6];
|
257 |
|
|
|
258 |
|
|
for(int i=0; i<6; i++)
|
259 |
|
|
{
|
260 |
|
|
output[i] = -1;
|
261 |
|
|
int[][] c = centerQuats[i];
|
262 |
2d697abd
|
Leszek Koltunski
|
int q = quats[8+i];
|
263 |
cc7d45d1
|
Leszek Koltunski
|
|
264 |
|
|
for(int j=0; j<6; j++)
|
265 |
|
|
if( c[j][0]==q || c[j][1]==q )
|
266 |
|
|
{
|
267 |
|
|
output[i] = j;
|
268 |
|
|
break;
|
269 |
|
|
}
|
270 |
|
|
}
|
271 |
|
|
|
272 |
|
|
return output;
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
276 |
|
|
|
277 |
|
|
private void fillCenterQuats(int[] quats, int[] perm)
|
278 |
|
|
{
|
279 |
8a489ebd
|
Leszek Koltunski
|
for(int i=0; i<6; i++) quats[8+i] = centerQuats[i][perm[i]][0];
|
280 |
cc7d45d1
|
Leszek Koltunski
|
}
|
281 |
|
|
|
282 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
283 |
|
|
|
284 |
2d697abd
|
Leszek Koltunski
|
private void fillUpToEvenPerm(int[] perm)
|
285 |
cc7d45d1
|
Leszek Koltunski
|
{
|
286 |
2d697abd
|
Leszek Koltunski
|
int min, max;
|
287 |
|
|
|
288 |
|
|
if( perm[0]!=0 && perm[1]!=0 ) min=0;
|
289 |
|
|
else if( perm[0]!=1 && perm[1]!=1 ) min=1;
|
290 |
|
|
else min=2;
|
291 |
|
|
|
292 |
|
|
if( perm[0]!=3 && perm[1]!=3 ) max=3;
|
293 |
|
|
else if( perm[0]!=2 && perm[1]!=2 ) max=2;
|
294 |
|
|
else max=1;
|
295 |
|
|
|
296 |
|
|
int diff = perm[1]-perm[0];
|
297 |
|
|
|
298 |
|
|
if( diff==-2 || diff==1 || diff==3 ) { perm[2]=min; perm[3]=max; }
|
299 |
|
|
else { perm[2]=max; perm[3]=min; }
|
300 |
cc7d45d1
|
Leszek Koltunski
|
}
|
301 |
|
|
|
302 |
e9bff328
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
303 |
|
|
|
304 |
|
|
public int[] getQuats(int index)
|
305 |
|
|
{
|
306 |
8a489ebd
|
Leszek Koltunski
|
int[] permFree = new int[4];
|
307 |
cc7d45d1
|
Leszek Koltunski
|
int center_perm_num = (index%360);
|
308 |
|
|
index /= 360;
|
309 |
|
|
int totalTwist = (index%2187);
|
310 |
8a489ebd
|
Leszek Koltunski
|
permFree[0] = (index/2187);
|
311 |
cc7d45d1
|
Leszek Koltunski
|
|
312 |
|
|
int[] quats = new int[14];
|
313 |
|
|
int[] center_perm = new int[6];
|
314 |
|
|
int[] twist = new int[8];
|
315 |
|
|
|
316 |
|
|
TablebaseHelpers.getEvenPermutationFromNum(center_perm, center_perm_num);
|
317 |
|
|
fillCenterQuats(quats,center_perm);
|
318 |
|
|
|
319 |
|
|
for(int i=0; i<7; i++)
|
320 |
|
|
{
|
321 |
|
|
twist[i] = (totalTwist%3);
|
322 |
|
|
totalTwist /= 3;
|
323 |
|
|
}
|
324 |
|
|
|
325 |
8a489ebd
|
Leszek Koltunski
|
int total = twist[FREE[0]]+twist[FREE[1]]+twist[FREE[2]];
|
326 |
cc7d45d1
|
Leszek Koltunski
|
twist[7] = ((6-total)%3);
|
327 |
8a489ebd
|
Leszek Koltunski
|
int sumFixedTwists = twist[FIXED[0]]+twist[FIXED[1]]+twist[FIXED[2]]+twist[FIXED[3]];
|
328 |
|
|
permFree[1] = freeIndex[permFree[0]][sumFixedTwists%3];
|
329 |
|
|
fillUpToEvenPerm(permFree);
|
330 |
|
|
fillInQuats(quats,permFree,twist);
|
331 |
cc7d45d1
|
Leszek Koltunski
|
|
332 |
|
|
return quats;
|
333 |
e9bff328
|
Leszek Koltunski
|
}
|
334 |
|
|
|
335 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
336 |
|
|
|
337 |
|
|
public int getIndex(int[] quats)
|
338 |
|
|
{
|
339 |
cc7d45d1
|
Leszek Koltunski
|
int[] center_perm = computeCenterPerm(quats);
|
340 |
|
|
int center_perm_num = TablebaseHelpers.computeEvenPermutationNum(center_perm);
|
341 |
|
|
int[] twist = new int[8];
|
342 |
|
|
computeCornerTwists(twist,quats);
|
343 |
|
|
int totalTwist = twist[0]+ 3*(twist[1]+ 3*(twist[2]+ 3*(twist[3]+ 3*(twist[4]+ 3*(twist[5]+ 3*twist[6])))));
|
344 |
2d697abd
|
Leszek Koltunski
|
int locationOfFree0 = computeLocation(0,quats[1]);
|
345 |
|
|
|
346 |
cc7d45d1
|
Leszek Koltunski
|
return center_perm_num+ 360*(totalTwist + 2187*locationOfFree0);
|
347 |
e9bff328
|
Leszek Koltunski
|
}
|
348 |
|
|
}
|