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 android.content.res.Resources;
|
17 |
|
|
|
18 |
|
|
import org.distorted.library.type.Static3D;
|
19 |
74cc695a
|
Leszek Koltunski
|
import org.distorted.objectlib.R;
|
20 |
b8519939
|
Leszek Koltunski
|
|
21 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
22 |
|
|
|
23 |
|
|
public class TablebasesPyraminx extends TablebasesAbstract
|
24 |
|
|
{
|
25 |
d8003f3a
|
Leszek Koltunski
|
public static final int[][] EDGE_QUATS = new int[][]
|
26 |
|
|
{
|
27 |
|
|
{ 0,10}, // even-odd quat (i.e. even-odd twist of the relevant edge piece)
|
28 |
|
|
{ 1, 7},
|
29 |
|
|
{ 4, 8},
|
30 |
|
|
{ 2, 6},
|
31 |
|
|
{ 3, 5},
|
32 |
f32c546d
|
Leszek Koltunski
|
{11, 9}
|
33 |
d8003f3a
|
Leszek Koltunski
|
};
|
34 |
|
|
|
35 |
b8519939
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
|
|
|
37 |
|
|
public TablebasesPyraminx()
|
38 |
|
|
{
|
39 |
|
|
super();
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
|
|
public TablebasesPyraminx(Resources res)
|
45 |
|
|
{
|
46 |
74cc695a
|
Leszek Koltunski
|
super(res, R.raw.pyra_3_tablebase);
|
47 |
b8519939
|
Leszek Koltunski
|
}
|
48 |
|
|
|
49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50 |
|
|
|
51 |
|
|
int[][] getBasicAngles()
|
52 |
|
|
{
|
53 |
|
|
int[] tmp = {3,3};
|
54 |
|
|
return new int[][] { tmp,tmp,tmp,tmp };
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
|
59 |
|
|
Static3D[] getRotationAxis()
|
60 |
|
|
{
|
61 |
ccd8a6f2
|
Leszek Koltunski
|
return new Static3D[]
|
62 |
|
|
{
|
63 |
|
|
new Static3D( 0,-SQ3/3,-SQ6/3),
|
64 |
|
|
new Static3D( 0,-SQ3/3, SQ6/3),
|
65 |
|
|
new Static3D( SQ6/3, SQ3/3, 0),
|
66 |
|
|
new Static3D(-SQ6/3, SQ3/3, 0),
|
67 |
|
|
};
|
68 |
b8519939
|
Leszek Koltunski
|
}
|
69 |
|
|
|
70 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71 |
|
|
|
72 |
|
|
float[][] getPosition()
|
73 |
|
|
{
|
74 |
|
|
return new float[][]
|
75 |
|
|
{
|
76 |
|
|
{ 0.0f,-SQ2/4, 0.5f},
|
77 |
|
|
{ 0.0f,-SQ2/4,-0.5f},
|
78 |
|
|
{-0.5f, SQ2/4, 0.0f},
|
79 |
|
|
{ 0.5f, SQ2/4, 0.0f},
|
80 |
|
|
|
81 |
74cc695a
|
Leszek Koltunski
|
{ 0.0f,-SQ2/2, 0.0f}, // index=0 has the quats already set up so that
|
82 |
|
|
{ 0.0f,-SQ2/2, 0.0f}, // all the edges fall into right spots, so here
|
83 |
|
|
{ 0.0f,-SQ2/2, 0.0f}, // they need to be all in one place
|
84 |
b8519939
|
Leszek Koltunski
|
{ 0.0f,-SQ2/2, 0.0f},
|
85 |
bf890718
|
Leszek Koltunski
|
{ 0.0f,-SQ2/2, 0.0f},
|
86 |
|
|
{ 0.0f,-SQ2/2, 0.0f},
|
87 |
b8519939
|
Leszek Koltunski
|
};
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
|
92 |
|
|
float[][] getCuts()
|
93 |
|
|
{
|
94 |
|
|
float[] cut = { 0.25f*(SQ6/3) };
|
95 |
|
|
return new float[][] { cut,cut,cut,cut };
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
99 |
|
|
|
100 |
|
|
boolean[][] getRotatable()
|
101 |
|
|
{
|
102 |
|
|
boolean[] tmp = new boolean[] {false,true};
|
103 |
|
|
return new boolean[][] { tmp,tmp,tmp,tmp };
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107 |
|
|
// specifically for the tablebase
|
108 |
6d637f71
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
|
110 |
|
|
private void addMove(int[] move, int axis, int twist)
|
111 |
|
|
{
|
112 |
|
|
move[0] = axis;
|
113 |
|
|
move[1] = (1<<2);
|
114 |
|
|
move[2] = (twist==2 ? -1:twist);
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
118 |
|
|
|
119 |
|
|
private int[][] constructTipMoves(int[] twist)
|
120 |
|
|
{
|
121 |
|
|
int total = 0;
|
122 |
|
|
|
123 |
|
|
for(int i=0; i<4; i++)
|
124 |
|
|
if( twist[i]!=0 ) total++;
|
125 |
|
|
|
126 |
|
|
if( total>0 )
|
127 |
|
|
{
|
128 |
|
|
int[][] moves = new int[total][3];
|
129 |
|
|
|
130 |
|
|
int index=0;
|
131 |
|
|
if( twist[0]!=0 ) { addMove(moves[index],1,twist[0]); index++; }
|
132 |
|
|
if( twist[1]!=0 ) { addMove(moves[index],0,twist[1]); index++; }
|
133 |
|
|
if( twist[2]!=0 ) { addMove(moves[index],3,twist[2]); index++; }
|
134 |
|
|
if( twist[3]!=0 ) { addMove(moves[index],2,twist[3]); }
|
135 |
|
|
|
136 |
|
|
return moves;
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
return null;
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
143 |
|
|
// extra = cornerTips
|
144 |
|
|
|
145 |
|
|
@Override
|
146 |
|
|
int[][] extraInfo(int[][] moves, int[] extra)
|
147 |
|
|
{
|
148 |
|
|
int[][] tipMoves = constructTipMoves(extra);
|
149 |
|
|
|
150 |
|
|
int len1 = ( moves==null ? 0: moves.length);
|
151 |
|
|
int len2 = (tipMoves==null ? 0:tipMoves.length);
|
152 |
|
|
|
153 |
|
|
int[][] ret = new int[len1+len2][3];
|
154 |
|
|
|
155 |
|
|
if( len1>0 ) System.arraycopy( moves, 0, ret, 0, len1);
|
156 |
|
|
if( len2>0 ) System.arraycopy(tipMoves, 0, ret, len1, len2);
|
157 |
|
|
|
158 |
|
|
return ret;
|
159 |
|
|
}
|
160 |
|
|
|
161 |
b8519939
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
162 |
|
|
|
163 |
|
|
int getSize()
|
164 |
|
|
{
|
165 |
|
|
return 933120; // see https://www.jaapsch.net/puzzles/pyraminx.htm
|
166 |
|
|
}
|
167 |
|
|
|
168 |
c0266cb1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
169 |
|
|
|
170 |
6d637f71
|
Leszek Koltunski
|
int getMinScramble()
|
171 |
c0266cb1
|
Leszek Koltunski
|
{
|
172 |
|
|
return 9;
|
173 |
|
|
}
|
174 |
|
|
|
175 |
b9f8919d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176 |
|
|
|
177 |
d8003f3a
|
Leszek Koltunski
|
public static void getEdgePermutation(int[] output, int[] quats, int index)
|
178 |
|
|
{
|
179 |
|
|
for(int i=0; i<6; i++ )
|
180 |
|
|
{
|
181 |
|
|
int quat = quats[i+index];
|
182 |
|
|
|
183 |
|
|
for(int j=0; j<6; j++)
|
184 |
|
|
{
|
185 |
|
|
int[] edge = EDGE_QUATS[j];
|
186 |
|
|
if( quat==edge[0] || quat==edge[1] ) { output[i]=j; break; }
|
187 |
|
|
}
|
188 |
|
|
}
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
192 |
|
|
|
193 |
|
|
public static void getEdgeTwist(int[] output, int[] quats, int index)
|
194 |
b9f8919d
|
Leszek Koltunski
|
{
|
195 |
d8003f3a
|
Leszek Koltunski
|
for(int i=0; i<6; i++)
|
196 |
|
|
{
|
197 |
|
|
int quat = quats[i+index];
|
198 |
|
|
|
199 |
|
|
for(int j=0; j<6; j++)
|
200 |
|
|
{
|
201 |
|
|
int[] edge = EDGE_QUATS[j];
|
202 |
|
|
if( quat==edge[0] ) { output[i]=0; break; }
|
203 |
|
|
if( quat==edge[1] ) { output[i]=1; break; }
|
204 |
|
|
}
|
205 |
|
|
}
|
206 |
|
|
}
|
207 |
|
|
|
208 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
209 |
b9f8919d
|
Leszek Koltunski
|
|
210 |
d8003f3a
|
Leszek Koltunski
|
private void getEdgeQuats(int twist, int[] perm, int[] output)
|
211 |
|
|
{
|
212 |
f32c546d
|
Leszek Koltunski
|
int totalTwist = 0;
|
213 |
|
|
|
214 |
|
|
for(int i=0; i<5; i++)
|
215 |
d8003f3a
|
Leszek Koltunski
|
{
|
216 |
|
|
int p = perm[i];
|
217 |
f32c546d
|
Leszek Koltunski
|
int t = (twist%2);
|
218 |
d8003f3a
|
Leszek Koltunski
|
twist/=2;
|
219 |
bf890718
|
Leszek Koltunski
|
output[i+4] = EDGE_QUATS[p][t];
|
220 |
f32c546d
|
Leszek Koltunski
|
|
221 |
|
|
totalTwist += t;
|
222 |
d8003f3a
|
Leszek Koltunski
|
}
|
223 |
f32c546d
|
Leszek Koltunski
|
|
224 |
|
|
int p = perm[5];
|
225 |
|
|
int t = (totalTwist%2)==0 ? 0:1;
|
226 |
|
|
output[9] = EDGE_QUATS[p][t];
|
227 |
d8003f3a
|
Leszek Koltunski
|
}
|
228 |
|
|
|
229 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
230 |
|
|
|
231 |
|
|
private int getVertexTwist(int[] quats)
|
232 |
|
|
{
|
233 |
|
|
int twist = 0;
|
234 |
|
|
|
235 |
|
|
if( quats[3]==5 ) twist += 1;
|
236 |
|
|
if( quats[3]==6 ) twist += 2;
|
237 |
|
|
twist *= 3;
|
238 |
|
|
if( quats[2]==7 ) twist += 1;
|
239 |
|
|
if( quats[2]==8 ) twist += 2;
|
240 |
|
|
twist *= 3;
|
241 |
|
|
if( quats[1]==1 ) twist += 1;
|
242 |
|
|
if( quats[1]==2 ) twist += 2;
|
243 |
|
|
twist *= 3;
|
244 |
|
|
if( quats[0]==3 ) twist += 1;
|
245 |
|
|
if( quats[0]==4 ) twist += 2;
|
246 |
|
|
|
247 |
|
|
return twist;
|
248 |
|
|
}
|
249 |
|
|
|
250 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
251 |
|
|
|
252 |
|
|
private void getVertexQuats(int twist, int[] output)
|
253 |
|
|
{
|
254 |
|
|
switch(twist%3)
|
255 |
|
|
{
|
256 |
|
|
case 0: output[0]=0; break;
|
257 |
|
|
case 1: output[0]=3; break;
|
258 |
|
|
case 2: output[0]=4; break;
|
259 |
|
|
}
|
260 |
|
|
twist /= 3;
|
261 |
|
|
|
262 |
|
|
switch(twist%3)
|
263 |
|
|
{
|
264 |
|
|
case 0: output[1]=0; break;
|
265 |
|
|
case 1: output[1]=1; break;
|
266 |
|
|
case 2: output[1]=2; break;
|
267 |
|
|
}
|
268 |
|
|
twist /= 3;
|
269 |
|
|
|
270 |
|
|
switch(twist%3)
|
271 |
|
|
{
|
272 |
|
|
case 0: output[2]=0; break;
|
273 |
|
|
case 1: output[2]=7; break;
|
274 |
|
|
case 2: output[2]=8; break;
|
275 |
|
|
}
|
276 |
|
|
twist /= 3;
|
277 |
|
|
|
278 |
|
|
switch(twist%3)
|
279 |
|
|
{
|
280 |
|
|
case 0: output[3]=0; break;
|
281 |
|
|
case 1: output[3]=5; break;
|
282 |
|
|
case 2: output[3]=6; break;
|
283 |
|
|
}
|
284 |
b9f8919d
|
Leszek Koltunski
|
}
|
285 |
|
|
|
286 |
b8519939
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
287 |
|
|
|
288 |
f32c546d
|
Leszek Koltunski
|
public int[] getQuats(int index)
|
289 |
b8519939
|
Leszek Koltunski
|
{
|
290 |
d8003f3a
|
Leszek Koltunski
|
int vertexTwist = (index%81);
|
291 |
|
|
index /= 81;
|
292 |
|
|
int edgeTwist = (index%32);
|
293 |
|
|
int perm_num = index/32;
|
294 |
|
|
|
295 |
|
|
int[] quats = new int[10];
|
296 |
|
|
|
297 |
|
|
getVertexQuats(vertexTwist,quats);
|
298 |
|
|
int[] permutation = new int[6];
|
299 |
522d858e
|
Leszek Koltunski
|
TablebaseHelpers.getEvenPermutationFromNum(permutation,perm_num);
|
300 |
d8003f3a
|
Leszek Koltunski
|
getEdgeQuats(edgeTwist,permutation,quats);
|
301 |
|
|
|
302 |
|
|
return quats;
|
303 |
b8519939
|
Leszek Koltunski
|
}
|
304 |
|
|
|
305 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
306 |
|
|
|
307 |
f32c546d
|
Leszek Koltunski
|
public int getIndex(int[] quats)
|
308 |
b8519939
|
Leszek Koltunski
|
{
|
309 |
d8003f3a
|
Leszek Koltunski
|
int vertexTwist = getVertexTwist(quats);
|
310 |
|
|
int[] permutation = new int[6];
|
311 |
|
|
getEdgePermutation(permutation,quats,4);
|
312 |
|
|
int[] twist = new int[6];
|
313 |
|
|
getEdgeTwist(twist,quats,4);
|
314 |
|
|
|
315 |
|
|
int edgeTwist = twist[0]+ 2*(twist[1]+ 2*(twist[2]+ 2*(twist[3]+ 2*twist[4])));
|
316 |
|
|
int perm_num = TablebaseHelpers.computeEvenPermutationNum(permutation);
|
317 |
|
|
|
318 |
|
|
return vertexTwist + 81*(edgeTwist + 32*perm_num);
|
319 |
b8519939
|
Leszek Koltunski
|
}
|
320 |
|
|
}
|