1 |
b8519939
|
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.SQ2;
|
13 |
ccd8a6f2
|
Leszek Koltunski
|
import static org.distorted.objectlib.main.TwistyObject.SQ3;
|
14 |
b8519939
|
Leszek Koltunski
|
import static org.distorted.objectlib.main.TwistyObject.SQ6;
|
15 |
|
|
|
16 |
|
|
import org.distorted.library.type.Static3D;
|
17 |
74cc695a
|
Leszek Koltunski
|
import org.distorted.objectlib.R;
|
18 |
3103c3c8
|
Leszek Koltunski
|
import org.distorted.objectlib.helpers.OperatingSystemInterface;
|
19 |
b8519939
|
Leszek Koltunski
|
|
20 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
21 |
|
|
|
22 |
a8d83300
|
Leszek Koltunski
|
public class TBPyraminx extends TablebasesAbstract
|
23 |
b8519939
|
Leszek Koltunski
|
{
|
24 |
d8003f3a
|
Leszek Koltunski
|
public static final int[][] EDGE_QUATS = new int[][]
|
25 |
|
|
{
|
26 |
|
|
{ 0,10}, // even-odd quat (i.e. even-odd twist of the relevant edge piece)
|
27 |
|
|
{ 1, 7},
|
28 |
|
|
{ 4, 8},
|
29 |
|
|
{ 2, 6},
|
30 |
|
|
{ 3, 5},
|
31 |
f32c546d
|
Leszek Koltunski
|
{11, 9}
|
32 |
d8003f3a
|
Leszek Koltunski
|
};
|
33 |
|
|
|
34 |
b8519939
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
35 |
|
|
|
36 |
a8d83300
|
Leszek Koltunski
|
public TBPyraminx()
|
37 |
b8519939
|
Leszek Koltunski
|
{
|
38 |
|
|
super();
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
|
|
|
43 |
3103c3c8
|
Leszek Koltunski
|
public TBPyraminx(OperatingSystemInterface os)
|
44 |
b8519939
|
Leszek Koltunski
|
{
|
45 |
3103c3c8
|
Leszek Koltunski
|
super(os, R.raw.pyra_3_tablebase);
|
46 |
b8519939
|
Leszek Koltunski
|
}
|
47 |
|
|
|
48 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49 |
|
|
|
50 |
|
|
int[][] getBasicAngles()
|
51 |
|
|
{
|
52 |
|
|
int[] tmp = {3,3};
|
53 |
|
|
return new int[][] { tmp,tmp,tmp,tmp };
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57 |
|
|
|
58 |
|
|
Static3D[] getRotationAxis()
|
59 |
|
|
{
|
60 |
ccd8a6f2
|
Leszek Koltunski
|
return new Static3D[]
|
61 |
|
|
{
|
62 |
|
|
new Static3D( 0,-SQ3/3,-SQ6/3),
|
63 |
|
|
new Static3D( 0,-SQ3/3, SQ6/3),
|
64 |
|
|
new Static3D( SQ6/3, SQ3/3, 0),
|
65 |
|
|
new Static3D(-SQ6/3, SQ3/3, 0),
|
66 |
|
|
};
|
67 |
b8519939
|
Leszek Koltunski
|
}
|
68 |
|
|
|
69 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
|
71 |
|
|
float[][] getPosition()
|
72 |
|
|
{
|
73 |
|
|
return new float[][]
|
74 |
|
|
{
|
75 |
|
|
{ 0.0f,-SQ2/4, 0.5f},
|
76 |
|
|
{ 0.0f,-SQ2/4,-0.5f},
|
77 |
|
|
{-0.5f, SQ2/4, 0.0f},
|
78 |
|
|
{ 0.5f, SQ2/4, 0.0f},
|
79 |
|
|
|
80 |
74cc695a
|
Leszek Koltunski
|
{ 0.0f,-SQ2/2, 0.0f}, // index=0 has the quats already set up so that
|
81 |
|
|
{ 0.0f,-SQ2/2, 0.0f}, // all the edges fall into right spots, so here
|
82 |
|
|
{ 0.0f,-SQ2/2, 0.0f}, // they need to be all in one place
|
83 |
b8519939
|
Leszek Koltunski
|
{ 0.0f,-SQ2/2, 0.0f},
|
84 |
bf890718
|
Leszek Koltunski
|
{ 0.0f,-SQ2/2, 0.0f},
|
85 |
|
|
{ 0.0f,-SQ2/2, 0.0f},
|
86 |
b8519939
|
Leszek Koltunski
|
};
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90 |
|
|
|
91 |
|
|
float[][] getCuts()
|
92 |
|
|
{
|
93 |
|
|
float[] cut = { 0.25f*(SQ6/3) };
|
94 |
|
|
return new float[][] { cut,cut,cut,cut };
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
|
|
boolean[][] getRotatable()
|
100 |
|
|
{
|
101 |
|
|
boolean[] tmp = new boolean[] {false,true};
|
102 |
|
|
return new boolean[][] { tmp,tmp,tmp,tmp };
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106 |
|
|
// specifically for the tablebase
|
107 |
6d637f71
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108 |
|
|
|
109 |
|
|
private void addMove(int[] move, int axis, int twist)
|
110 |
|
|
{
|
111 |
|
|
move[0] = axis;
|
112 |
20df890a
|
Leszek Koltunski
|
move[1] = 4;
|
113 |
6d637f71
|
Leszek Koltunski
|
move[2] = (twist==2 ? -1:twist);
|
114 |
|
|
}
|
115 |
|
|
|
116 |
13fd91e7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117 |
|
|
|
118 |
|
|
private void includeTip(int[] move, int[] extra, int index)
|
119 |
|
|
{
|
120 |
|
|
move[1] = 6;
|
121 |
|
|
extra[index] += (move[2]==1 ? 2:1);
|
122 |
|
|
}
|
123 |
|
|
|
124 |
6d637f71
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
125 |
|
|
|
126 |
20df890a
|
Leszek Koltunski
|
private boolean failedInsertingTipMove(int[][] moves, int[] extra, int extraIndex, int axis)
|
127 |
6d637f71
|
Leszek Koltunski
|
{
|
128 |
20df890a
|
Leszek Koltunski
|
int numAxis = 0;
|
129 |
|
|
boolean ret = true;
|
130 |
13fd91e7
|
Leszek Koltunski
|
extra[extraIndex]+=3; // make sure extra is positive
|
131 |
6d637f71
|
Leszek Koltunski
|
|
132 |
20df890a
|
Leszek Koltunski
|
for( int[] move : moves )
|
133 |
|
|
{
|
134 |
|
|
if( move[0]==axis )
|
135 |
|
|
{
|
136 |
|
|
numAxis++;
|
137 |
13fd91e7
|
Leszek Koltunski
|
if( (numAxis==1 && (move[2]-extra[extraIndex])%3==0 ) || numAxis>=2 ) ret=false;
|
138 |
20df890a
|
Leszek Koltunski
|
}
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
int currAx = 0;
|
142 |
|
|
int numMoves = moves.length;
|
143 |
|
|
int foreIndex=-1;
|
144 |
|
|
int lastIndex = -1;
|
145 |
6d637f71
|
Leszek Koltunski
|
|
146 |
20df890a
|
Leszek Koltunski
|
for( int index=0; index<numMoves; index++ )
|
147 |
6d637f71
|
Leszek Koltunski
|
{
|
148 |
20df890a
|
Leszek Koltunski
|
int[] move = moves[index];
|
149 |
6d637f71
|
Leszek Koltunski
|
|
150 |
20df890a
|
Leszek Koltunski
|
if( move[0]==axis )
|
151 |
|
|
{
|
152 |
13fd91e7
|
Leszek Koltunski
|
if( currAx < numAxis-2 ) includeTip(move,extra,extraIndex);
|
153 |
|
|
else if( currAx == numAxis-2 ) foreIndex = index;
|
154 |
|
|
else if( currAx == numAxis-1 ) lastIndex = index;
|
155 |
20df890a
|
Leszek Koltunski
|
currAx++;
|
156 |
|
|
}
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
extra[extraIndex] = (extra[extraIndex]%3);
|
160 |
|
|
|
161 |
|
|
if( foreIndex>=0 )
|
162 |
|
|
{
|
163 |
|
|
int foreAngle = moves[foreIndex][2];
|
164 |
|
|
int lastAngle = moves[lastIndex][2];
|
165 |
6d637f71
|
Leszek Koltunski
|
|
166 |
20df890a
|
Leszek Koltunski
|
if( extra[extraIndex]==1 )
|
167 |
|
|
{
|
168 |
13fd91e7
|
Leszek Koltunski
|
if( foreAngle==1 ) includeTip(moves[foreIndex],extra,extraIndex);
|
169 |
20df890a
|
Leszek Koltunski
|
else
|
170 |
|
|
{
|
171 |
13fd91e7
|
Leszek Koltunski
|
includeTip(moves[lastIndex],extra,extraIndex);
|
172 |
|
|
if( lastAngle==-1 ) includeTip(moves[foreIndex],extra,extraIndex);
|
173 |
20df890a
|
Leszek Koltunski
|
}
|
174 |
|
|
}
|
175 |
|
|
else if( extra[extraIndex]==2 )
|
176 |
|
|
{
|
177 |
13fd91e7
|
Leszek Koltunski
|
if( foreAngle==-1 ) includeTip(moves[foreIndex],extra,extraIndex);
|
178 |
20df890a
|
Leszek Koltunski
|
else
|
179 |
|
|
{
|
180 |
13fd91e7
|
Leszek Koltunski
|
includeTip(moves[lastIndex],extra,extraIndex);
|
181 |
|
|
if( lastAngle==1 ) includeTip(moves[foreIndex],extra,extraIndex);
|
182 |
20df890a
|
Leszek Koltunski
|
}
|
183 |
|
|
}
|
184 |
6d637f71
|
Leszek Koltunski
|
}
|
185 |
20df890a
|
Leszek Koltunski
|
else if( lastIndex>=0 )
|
186 |
|
|
{
|
187 |
|
|
int lastAngle = moves[lastIndex][2];
|
188 |
6d637f71
|
Leszek Koltunski
|
|
189 |
13fd91e7
|
Leszek Koltunski
|
if( (extra[extraIndex]-lastAngle)%3 ==0 )
|
190 |
|
|
includeTip(moves[lastIndex],extra,extraIndex);
|
191 |
20df890a
|
Leszek Koltunski
|
}
|
192 |
|
|
|
193 |
|
|
extra[extraIndex] = (extra[extraIndex]%3);
|
194 |
|
|
|
195 |
|
|
return ret;
|
196 |
6d637f71
|
Leszek Koltunski
|
}
|
197 |
|
|
|
198 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
199 |
|
|
// extra = cornerTips
|
200 |
|
|
|
201 |
|
|
@Override
|
202 |
|
|
int[][] extraInfo(int[][] moves, int[] extra)
|
203 |
|
|
{
|
204 |
20df890a
|
Leszek Koltunski
|
int lenExtra = 0;
|
205 |
6d637f71
|
Leszek Koltunski
|
|
206 |
20df890a
|
Leszek Koltunski
|
if( failedInsertingTipMove(moves,extra,0,1) && extra[0]!=0 ) lenExtra++;
|
207 |
|
|
if( failedInsertingTipMove(moves,extra,1,0) && extra[1]!=0 ) lenExtra++;
|
208 |
|
|
if( failedInsertingTipMove(moves,extra,2,3) && extra[2]!=0 ) lenExtra++;
|
209 |
|
|
if( failedInsertingTipMove(moves,extra,3,2) && extra[3]!=0 ) lenExtra++;
|
210 |
6d637f71
|
Leszek Koltunski
|
|
211 |
20df890a
|
Leszek Koltunski
|
if( lenExtra>0 )
|
212 |
|
|
{
|
213 |
|
|
int[][] extraMoves = new int[lenExtra][3];
|
214 |
6d637f71
|
Leszek Koltunski
|
|
215 |
20df890a
|
Leszek Koltunski
|
int index=0;
|
216 |
|
|
if( extra[0]!=0 ) { addMove(extraMoves[index],1,extra[0]); index++; }
|
217 |
|
|
if( extra[1]!=0 ) { addMove(extraMoves[index],0,extra[1]); index++; }
|
218 |
|
|
if( extra[2]!=0 ) { addMove(extraMoves[index],3,extra[2]); index++; }
|
219 |
|
|
if( extra[3]!=0 ) { addMove(extraMoves[index],2,extra[3]); }
|
220 |
|
|
|
221 |
|
|
int len = moves.length;
|
222 |
|
|
int totalLen = len+lenExtra;
|
223 |
|
|
int[][] totalMoves = new int[totalLen][];
|
224 |
|
|
|
225 |
|
|
if( len>0 ) System.arraycopy(moves, 0, totalMoves, 0, len);
|
226 |
|
|
System.arraycopy(extraMoves, 0, totalMoves, len, lenExtra);
|
227 |
|
|
|
228 |
|
|
return totalMoves;
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
return moves;
|
232 |
6d637f71
|
Leszek Koltunski
|
}
|
233 |
|
|
|
234 |
b8519939
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
235 |
|
|
|
236 |
|
|
int getSize()
|
237 |
|
|
{
|
238 |
|
|
return 933120; // see https://www.jaapsch.net/puzzles/pyraminx.htm
|
239 |
|
|
}
|
240 |
|
|
|
241 |
c0266cb1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
242 |
|
|
|
243 |
6d637f71
|
Leszek Koltunski
|
int getMinScramble()
|
244 |
c0266cb1
|
Leszek Koltunski
|
{
|
245 |
|
|
return 9;
|
246 |
|
|
}
|
247 |
|
|
|
248 |
b9f8919d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
249 |
|
|
|
250 |
d8003f3a
|
Leszek Koltunski
|
public static void getEdgePermutation(int[] output, int[] quats, int index)
|
251 |
|
|
{
|
252 |
|
|
for(int i=0; i<6; i++ )
|
253 |
|
|
{
|
254 |
|
|
int quat = quats[i+index];
|
255 |
|
|
|
256 |
|
|
for(int j=0; j<6; j++)
|
257 |
|
|
{
|
258 |
|
|
int[] edge = EDGE_QUATS[j];
|
259 |
|
|
if( quat==edge[0] || quat==edge[1] ) { output[i]=j; break; }
|
260 |
|
|
}
|
261 |
|
|
}
|
262 |
|
|
}
|
263 |
|
|
|
264 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
265 |
|
|
|
266 |
|
|
public static void getEdgeTwist(int[] output, int[] quats, int index)
|
267 |
b9f8919d
|
Leszek Koltunski
|
{
|
268 |
d8003f3a
|
Leszek Koltunski
|
for(int i=0; i<6; i++)
|
269 |
|
|
{
|
270 |
|
|
int quat = quats[i+index];
|
271 |
|
|
|
272 |
|
|
for(int j=0; j<6; j++)
|
273 |
|
|
{
|
274 |
|
|
int[] edge = EDGE_QUATS[j];
|
275 |
|
|
if( quat==edge[0] ) { output[i]=0; break; }
|
276 |
|
|
if( quat==edge[1] ) { output[i]=1; break; }
|
277 |
|
|
}
|
278 |
|
|
}
|
279 |
|
|
}
|
280 |
|
|
|
281 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
282 |
b9f8919d
|
Leszek Koltunski
|
|
283 |
d8003f3a
|
Leszek Koltunski
|
private void getEdgeQuats(int twist, int[] perm, int[] output)
|
284 |
|
|
{
|
285 |
f32c546d
|
Leszek Koltunski
|
int totalTwist = 0;
|
286 |
|
|
|
287 |
|
|
for(int i=0; i<5; i++)
|
288 |
d8003f3a
|
Leszek Koltunski
|
{
|
289 |
|
|
int p = perm[i];
|
290 |
f32c546d
|
Leszek Koltunski
|
int t = (twist%2);
|
291 |
d8003f3a
|
Leszek Koltunski
|
twist/=2;
|
292 |
bf890718
|
Leszek Koltunski
|
output[i+4] = EDGE_QUATS[p][t];
|
293 |
f32c546d
|
Leszek Koltunski
|
|
294 |
|
|
totalTwist += t;
|
295 |
d8003f3a
|
Leszek Koltunski
|
}
|
296 |
f32c546d
|
Leszek Koltunski
|
|
297 |
|
|
int p = perm[5];
|
298 |
|
|
int t = (totalTwist%2)==0 ? 0:1;
|
299 |
|
|
output[9] = EDGE_QUATS[p][t];
|
300 |
d8003f3a
|
Leszek Koltunski
|
}
|
301 |
|
|
|
302 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
303 |
|
|
|
304 |
|
|
private int getVertexTwist(int[] quats)
|
305 |
|
|
{
|
306 |
|
|
int twist = 0;
|
307 |
|
|
|
308 |
|
|
if( quats[3]==5 ) twist += 1;
|
309 |
|
|
if( quats[3]==6 ) twist += 2;
|
310 |
|
|
twist *= 3;
|
311 |
|
|
if( quats[2]==7 ) twist += 1;
|
312 |
|
|
if( quats[2]==8 ) twist += 2;
|
313 |
|
|
twist *= 3;
|
314 |
|
|
if( quats[1]==1 ) twist += 1;
|
315 |
|
|
if( quats[1]==2 ) twist += 2;
|
316 |
|
|
twist *= 3;
|
317 |
|
|
if( quats[0]==3 ) twist += 1;
|
318 |
|
|
if( quats[0]==4 ) twist += 2;
|
319 |
|
|
|
320 |
|
|
return twist;
|
321 |
|
|
}
|
322 |
|
|
|
323 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
324 |
|
|
|
325 |
|
|
private void getVertexQuats(int twist, int[] output)
|
326 |
|
|
{
|
327 |
|
|
switch(twist%3)
|
328 |
|
|
{
|
329 |
|
|
case 0: output[0]=0; break;
|
330 |
|
|
case 1: output[0]=3; break;
|
331 |
|
|
case 2: output[0]=4; break;
|
332 |
|
|
}
|
333 |
|
|
twist /= 3;
|
334 |
|
|
|
335 |
|
|
switch(twist%3)
|
336 |
|
|
{
|
337 |
|
|
case 0: output[1]=0; break;
|
338 |
|
|
case 1: output[1]=1; break;
|
339 |
|
|
case 2: output[1]=2; break;
|
340 |
|
|
}
|
341 |
|
|
twist /= 3;
|
342 |
|
|
|
343 |
|
|
switch(twist%3)
|
344 |
|
|
{
|
345 |
|
|
case 0: output[2]=0; break;
|
346 |
|
|
case 1: output[2]=7; break;
|
347 |
|
|
case 2: output[2]=8; break;
|
348 |
|
|
}
|
349 |
|
|
twist /= 3;
|
350 |
|
|
|
351 |
|
|
switch(twist%3)
|
352 |
|
|
{
|
353 |
|
|
case 0: output[3]=0; break;
|
354 |
|
|
case 1: output[3]=5; break;
|
355 |
|
|
case 2: output[3]=6; break;
|
356 |
|
|
}
|
357 |
b9f8919d
|
Leszek Koltunski
|
}
|
358 |
|
|
|
359 |
b8519939
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
360 |
|
|
|
361 |
f32c546d
|
Leszek Koltunski
|
public int[] getQuats(int index)
|
362 |
b8519939
|
Leszek Koltunski
|
{
|
363 |
d8003f3a
|
Leszek Koltunski
|
int vertexTwist = (index%81);
|
364 |
|
|
index /= 81;
|
365 |
|
|
int edgeTwist = (index%32);
|
366 |
|
|
int perm_num = index/32;
|
367 |
|
|
|
368 |
|
|
int[] quats = new int[10];
|
369 |
|
|
|
370 |
|
|
getVertexQuats(vertexTwist,quats);
|
371 |
|
|
int[] permutation = new int[6];
|
372 |
522d858e
|
Leszek Koltunski
|
TablebaseHelpers.getEvenPermutationFromNum(permutation,perm_num);
|
373 |
d8003f3a
|
Leszek Koltunski
|
getEdgeQuats(edgeTwist,permutation,quats);
|
374 |
|
|
|
375 |
|
|
return quats;
|
376 |
b8519939
|
Leszek Koltunski
|
}
|
377 |
|
|
|
378 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
379 |
|
|
|
380 |
f32c546d
|
Leszek Koltunski
|
public int getIndex(int[] quats)
|
381 |
b8519939
|
Leszek Koltunski
|
{
|
382 |
d8003f3a
|
Leszek Koltunski
|
int vertexTwist = getVertexTwist(quats);
|
383 |
|
|
int[] permutation = new int[6];
|
384 |
|
|
getEdgePermutation(permutation,quats,4);
|
385 |
|
|
int[] twist = new int[6];
|
386 |
|
|
getEdgeTwist(twist,quats,4);
|
387 |
|
|
|
388 |
|
|
int edgeTwist = twist[0]+ 2*(twist[1]+ 2*(twist[2]+ 2*(twist[3]+ 2*twist[4])));
|
389 |
|
|
int perm_num = TablebaseHelpers.computeEvenPermutationNum(permutation);
|
390 |
|
|
|
391 |
|
|
return vertexTwist + 81*(edgeTwist + 32*perm_num);
|
392 |
b8519939
|
Leszek Koltunski
|
}
|
393 |
|
|
}
|