1 |
8b57a8f9
|
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 |
|
|
import static org.distorted.objectlib.main.TwistyObject.SQ3;
|
14 |
|
|
import static org.distorted.objectlib.main.TwistyObject.SQ6;
|
15 |
|
|
import static org.distorted.objectlib.objects.TwistyJing.F;
|
16 |
|
|
|
17 |
|
|
import android.content.res.Resources;
|
18 |
|
|
|
19 |
|
|
import org.distorted.library.type.Static3D;
|
20 |
|
|
import org.distorted.objectlib.R;
|
21 |
|
|
|
22 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
23 |
|
|
|
24 |
|
|
public class TBJing extends TablebasesAbstract
|
25 |
|
|
{
|
26 |
|
|
static final int[][][] QUATS_EDGE = new int[][][]
|
27 |
|
|
{
|
28 |
|
|
{ { 0,10},{ 5, 3},{ 8, 4},{ 6, 2},{ 7, 1},{ 9,11} },
|
29 |
|
|
{ { 6, 4},{ 0,11},{ 3, 1},{ 5, 7},{ 9,10},{ 2, 8} },
|
30 |
|
|
{ { 7, 3},{ 4, 2},{ 0, 9},{11,10},{ 8, 6},{ 5, 1} },
|
31 |
|
|
{ { 5, 1},{ 6, 8},{11,10},{ 0, 9},{ 2, 4},{ 7, 3} },
|
32 |
|
|
{ { 8, 2},{ 9,10},{ 7, 5},{ 1, 3},{ 0,11},{ 4, 6} },
|
33 |
|
|
{ { 9,11},{ 1, 7},{ 6, 2},{ 8, 4},{ 3, 5},{ 0,10} }
|
34 |
|
|
};
|
35 |
|
|
|
36 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37 |
|
|
|
38 |
|
|
public TBJing()
|
39 |
|
|
{
|
40 |
|
|
super();
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44 |
|
|
|
45 |
|
|
public TBJing(Resources res)
|
46 |
|
|
{
|
47 |
|
|
super(res, R.raw.pyra_3_tablebase);
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51 |
|
|
|
52 |
|
|
int[][] getBasicAngles()
|
53 |
|
|
{
|
54 |
|
|
int[] tmp = {3,3};
|
55 |
|
|
return new int[][] { tmp,tmp,tmp,tmp };
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59 |
|
|
|
60 |
|
|
Static3D[] getRotationAxis()
|
61 |
|
|
{
|
62 |
|
|
return new Static3D[]
|
63 |
|
|
{
|
64 |
|
|
new Static3D( 0,-SQ3/3,-SQ6/3),
|
65 |
|
|
new Static3D( 0,-SQ3/3, SQ6/3),
|
66 |
|
|
new Static3D( SQ6/3, SQ3/3, 0),
|
67 |
|
|
new Static3D(-SQ6/3, SQ3/3, 0),
|
68 |
|
|
};
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
72 |
|
|
|
73 |
|
|
float[][] getPosition()
|
74 |
|
|
{
|
75 |
|
|
return new float[][]
|
76 |
|
|
{
|
77 |
|
|
{ 0.000f, -SQ2/2, 1.000f },
|
78 |
|
|
{ 0.000f, -SQ2/2,-1.000f },
|
79 |
|
|
{-1.000f, SQ2/2, 0.000f },
|
80 |
|
|
{ 1.000f, SQ2/2, 0.000f },
|
81 |
|
|
|
82 |
|
|
{ 0.000f, -SQ2/2, 0.000f },
|
83 |
|
|
{-0.500f, 0.000f, 0.500f },
|
84 |
|
|
{ 0.500f, 0.000f, 0.500f },
|
85 |
|
|
{-0.500f, 0.000f,-0.500f },
|
86 |
|
|
{ 0.500f, 0.000f,-0.500f },
|
87 |
|
|
{ 0.000f, SQ2/2, 0.000f },
|
88 |
|
|
|
89 |
|
|
{ 0.000f, SQ2/6, 1.0f/3 },
|
90 |
|
|
{ 0.000f, SQ2/6,-1.0f/3 },
|
91 |
|
|
{-1.0f/3, -SQ2/6, 0.000f },
|
92 |
|
|
{ 1.0f/3, -SQ2/6, 0.000f },
|
93 |
|
|
};
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97 |
|
|
|
98 |
|
|
float[][] getCuts()
|
99 |
|
|
{
|
100 |
|
|
float[] cut = { (F-0.5f)*(SQ6/3) };
|
101 |
|
|
return new float[][] { cut,cut,cut,cut };
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
105 |
|
|
|
106 |
|
|
boolean[][] getRotatable()
|
107 |
|
|
{
|
108 |
|
|
boolean[] tmp = new boolean[] {false,true};
|
109 |
|
|
return new boolean[][] { tmp,tmp,tmp,tmp };
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113 |
|
|
// specifically for the tablebase
|
114 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115 |
|
|
|
116 |
|
|
int getSize()
|
117 |
|
|
{
|
118 |
|
|
return 3732480; // see https://www.jaapsch.net/puzzles/pyraminx.htm
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
122 |
|
|
|
123 |
|
|
int getMinScramble()
|
124 |
|
|
{
|
125 |
|
|
return 9;
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129 |
|
|
|
130 |
|
|
public static void getEdgePermTwist(int[] perm, int[] twist, int[] quats, int index)
|
131 |
|
|
{
|
132 |
|
|
for(int i=0; i<6; i++)
|
133 |
|
|
{
|
134 |
|
|
int quat = quats[i+index];
|
135 |
|
|
|
136 |
|
|
for(int j=0; j<6; j++)
|
137 |
|
|
{
|
138 |
|
|
int[] edge = QUATS_EDGE[i][j];
|
139 |
|
|
if( quat==edge[0] ) { perm[i]=j; twist[i]=0; break; }
|
140 |
|
|
if( quat==edge[1] ) { perm[i]=j; twist[i]=1; break; }
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146 |
|
|
|
147 |
|
|
private int getVertexTwist(int[] quats)
|
148 |
|
|
{
|
149 |
|
|
int twist = 0;
|
150 |
|
|
|
151 |
|
|
if( quats[3]==5 ) twist += 1;
|
152 |
|
|
if( quats[3]==6 ) twist += 2;
|
153 |
|
|
twist *= 3;
|
154 |
|
|
if( quats[2]==7 ) twist += 1;
|
155 |
|
|
if( quats[2]==8 ) twist += 2;
|
156 |
|
|
twist *= 3;
|
157 |
|
|
if( quats[1]==1 ) twist += 1;
|
158 |
|
|
if( quats[1]==2 ) twist += 2;
|
159 |
|
|
twist *= 3;
|
160 |
|
|
if( quats[0]==3 ) twist += 1;
|
161 |
|
|
if( quats[0]==4 ) twist += 2;
|
162 |
|
|
|
163 |
|
|
return twist;
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
167 |
|
|
|
168 |
|
|
private void getVertexQuats(int twist, int[] output)
|
169 |
|
|
{
|
170 |
|
|
switch(twist%3)
|
171 |
|
|
{
|
172 |
|
|
case 0: output[0]=0; break;
|
173 |
|
|
case 1: output[0]=3; break;
|
174 |
|
|
case 2: output[0]=4; break;
|
175 |
|
|
}
|
176 |
|
|
twist /= 3;
|
177 |
|
|
|
178 |
|
|
switch(twist%3)
|
179 |
|
|
{
|
180 |
|
|
case 0: output[1]=0; break;
|
181 |
|
|
case 1: output[1]=1; break;
|
182 |
|
|
case 2: output[1]=2; break;
|
183 |
|
|
}
|
184 |
|
|
twist /= 3;
|
185 |
|
|
|
186 |
|
|
switch(twist%3)
|
187 |
|
|
{
|
188 |
|
|
case 0: output[2]=0; break;
|
189 |
|
|
case 1: output[2]=7; break;
|
190 |
|
|
case 2: output[2]=8; break;
|
191 |
|
|
}
|
192 |
|
|
twist /= 3;
|
193 |
|
|
|
194 |
|
|
switch(twist%3)
|
195 |
|
|
{
|
196 |
|
|
case 0: output[3]=0; break;
|
197 |
|
|
case 1: output[3]=5; break;
|
198 |
|
|
case 2: output[3]=6; break;
|
199 |
|
|
}
|
200 |
|
|
}
|
201 |
|
|
|
202 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
203 |
|
|
|
204 |
|
|
private void getEdgeQuats(int twist, int[] perm, int[] output)
|
205 |
|
|
{
|
206 |
|
|
int totalTwist = 0;
|
207 |
|
|
|
208 |
|
|
for(int i=0; i<5; i++)
|
209 |
|
|
{
|
210 |
|
|
int p = perm[i];
|
211 |
|
|
int t = (twist%2);
|
212 |
|
|
twist/=2;
|
213 |
|
|
output[i+4] = QUATS_EDGE[i][p][t];
|
214 |
|
|
|
215 |
|
|
totalTwist += t;
|
216 |
|
|
}
|
217 |
|
|
|
218 |
|
|
int p = perm[5];
|
219 |
|
|
int t = (totalTwist%2)==0 ? 0:1;
|
220 |
|
|
output[9] = QUATS_EDGE[5][p][t];
|
221 |
|
|
}
|
222 |
|
|
|
223 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
224 |
|
|
|
225 |
|
|
public int[] getQuats(int index)
|
226 |
|
|
{
|
227 |
|
|
int green_face = (index%4);
|
228 |
|
|
index /= 4;
|
229 |
|
|
int vertexTwist = (index%81);
|
230 |
|
|
index /= 81;
|
231 |
|
|
int edgeTwist = (index%32);
|
232 |
|
|
int perm_num = index/32;
|
233 |
|
|
|
234 |
|
|
int[] quats = new int[14];
|
235 |
|
|
|
236 |
|
|
getVertexQuats(vertexTwist,quats);
|
237 |
|
|
int[] permutation = new int[6];
|
238 |
|
|
TablebaseHelpers.getEvenPermutationFromNum(permutation,perm_num);
|
239 |
|
|
getEdgeQuats(edgeTwist,permutation,quats);
|
240 |
|
|
|
241 |
|
|
// we don't need to care about the values of the last 3 quats, but do include them.
|
242 |
|
|
switch(green_face)
|
243 |
|
|
{
|
244 |
|
|
case 0: quats[10] = 0; break;
|
245 |
|
|
case 1: quats[10] = 5; break;
|
246 |
|
|
case 2: quats[10] = 4; break;
|
247 |
|
|
case 3: quats[10] = 3; break;
|
248 |
|
|
}
|
249 |
|
|
|
250 |
|
|
return quats;
|
251 |
|
|
}
|
252 |
|
|
|
253 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
254 |
|
|
|
255 |
|
|
public int getIndex(int[] quats)
|
256 |
|
|
{
|
257 |
|
|
int vertexTwist = getVertexTwist(quats);
|
258 |
|
|
int[] permutation = new int[6];
|
259 |
|
|
int[] twist = new int[6];
|
260 |
|
|
getEdgePermTwist(permutation,twist,quats,4);
|
261 |
|
|
|
262 |
|
|
int edgeTwist = twist[0]+ 2*(twist[1]+ 2*(twist[2]+ 2*(twist[3]+ 2*twist[4])));
|
263 |
|
|
int perm_num = TablebaseHelpers.computeEvenPermutationNum(permutation);
|
264 |
|
|
|
265 |
|
|
int green_face = -1;
|
266 |
|
|
switch(quats[10])
|
267 |
|
|
{
|
268 |
|
|
case 0: case 1: case 2: green_face=0; break;
|
269 |
|
|
case 5: case 8: case 10: green_face=1; break;
|
270 |
|
|
case 4: case 7: case 11: green_face=2; break;
|
271 |
|
|
case 3: case 6: case 9: green_face=3; break;
|
272 |
|
|
}
|
273 |
|
|
/*
|
274 |
|
|
for(int i=0; i<6; i++) android.util.Log.e("D", "edge perm = "+permutation[i]);
|
275 |
|
|
android.util.Log.e("D", "ret: green_face="+green_face+" vertTwist="+vertexTwist+" edgeTwist="+edgeTwist+" perm: "+perm_num);
|
276 |
|
|
*/
|
277 |
|
|
return green_face + 4*(vertexTwist + 81*(edgeTwist + 32*perm_num));
|
278 |
|
|
}
|
279 |
|
|
}
|