1 |
739a64d4
|
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 |
b9ee3f6e
|
Leszek Koltunski
|
import static org.distorted.objectlib.main.TwistyObject.SQ2;
|
13 |
739a64d4
|
Leszek Koltunski
|
import static org.distorted.objectlib.main.TwistyObject.SQ3;
|
14 |
|
|
import static org.distorted.objectlib.main.TwistyObject.SQ6;
|
15 |
|
|
|
16 |
|
|
import org.distorted.library.type.Static3D;
|
17 |
|
|
import org.distorted.objectlib.R;
|
18 |
3103c3c8
|
Leszek Koltunski
|
import org.distorted.objectlib.helpers.OperatingSystemInterface;
|
19 |
739a64d4
|
Leszek Koltunski
|
|
20 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
21 |
|
|
|
22 |
a8d83300
|
Leszek Koltunski
|
public class TBSkewbDiamond extends TablebasesAbstract
|
23 |
739a64d4
|
Leszek Koltunski
|
{
|
24 |
4fc4e364
|
Leszek Koltunski
|
private static final int[][][] FREE_CENTER =
|
25 |
|
|
{
|
26 |
|
|
{ {0,5, 6}, {1,4,10}, {2,7, 9}, {3,8,11} },
|
27 |
|
|
{ {2,3,10}, {0,7, 8}, {1,6,11}, {4,5, 9} },
|
28 |
|
|
{ {1,8, 9}, {2,5,11}, {0,3, 4}, {6,7,10} },
|
29 |
|
|
{ {4,7,11}, {3,6, 9}, {5,8,10}, {0,1, 2} }
|
30 |
|
|
};
|
31 |
|
|
|
32 |
59d4ca91
|
Leszek Koltunski
|
public static final int[][][] CORNER_QUATS =
|
33 |
4fc4e364
|
Leszek Koltunski
|
{
|
34 |
59d4ca91
|
Leszek Koltunski
|
{ {0,9},{2,4},{10,11},{8,6},{1,5},{3,7} }, // order of each pair determines the twist.
|
35 |
|
|
{ {1,3},{0,11},{5,7},{10,9},{2,8},{6,4} },
|
36 |
|
|
{ {10,11},{6,8},{0,9},{4,2},{7,3},{5,1} },
|
37 |
|
|
{ {7,5},{10,9},{3,1},{0,11},{6,4},{2,8} },
|
38 |
|
|
{ {2,6},{1,7},{8,4},{5,3},{0,10},{9,11} },
|
39 |
|
|
{ {4,8},{5,3},{6,2},{1,7},{9,11},{0,10} }
|
40 |
4fc4e364
|
Leszek Koltunski
|
};
|
41 |
|
|
|
42 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
a8d83300
|
Leszek Koltunski
|
public TBSkewbDiamond()
|
45 |
739a64d4
|
Leszek Koltunski
|
{
|
46 |
|
|
super();
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50 |
|
|
|
51 |
3103c3c8
|
Leszek Koltunski
|
public TBSkewbDiamond(OperatingSystemInterface os)
|
52 |
739a64d4
|
Leszek Koltunski
|
{
|
53 |
3103c3c8
|
Leszek Koltunski
|
super(os, R.raw.diam_2_tablebase);
|
54 |
739a64d4
|
Leszek Koltunski
|
}
|
55 |
|
|
|
56 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57 |
|
|
|
58 |
|
|
int[][] getBasicAngles()
|
59 |
|
|
{
|
60 |
|
|
int[] tmp = {3,3};
|
61 |
|
|
return new int[][] { tmp,tmp,tmp,tmp };
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
65 |
|
|
|
66 |
|
|
Static3D[] getRotationAxis()
|
67 |
|
|
{
|
68 |
|
|
return new Static3D[]
|
69 |
|
|
{
|
70 |
|
|
new Static3D( SQ6/3, SQ3/3, 0),
|
71 |
|
|
new Static3D(-SQ6/3, SQ3/3, 0),
|
72 |
|
|
new Static3D( 0,-SQ3/3,-SQ6/3),
|
73 |
|
|
new Static3D( 0,-SQ3/3, SQ6/3)
|
74 |
|
|
};
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78 |
|
|
|
79 |
|
|
float[][] getPosition()
|
80 |
|
|
{
|
81 |
|
|
return new float[][]
|
82 |
|
|
{
|
83 |
b9ee3f6e
|
Leszek Koltunski
|
{ 0.5f, 0.0f, 0.5f},
|
84 |
|
|
{ 0.5f, 0.0f, -0.5f},
|
85 |
|
|
{-0.5f, 0.0f, -0.5f},
|
86 |
|
|
{-0.5f, 0.0f, 0.5f},
|
87 |
|
|
{ 0.0f, SQ2/2, 0.0f},
|
88 |
|
|
{ 0.0f,-SQ2/2, 0.0f},
|
89 |
|
|
|
90 |
8499ba3d
|
Leszek Koltunski
|
{ 0.0f, SQ2/4, 0.5f},
|
91 |
b9ee3f6e
|
Leszek Koltunski
|
{ 0.5f, SQ2/4, 0.0f},
|
92 |
|
|
{ 0.0f, SQ2/4,-0.5f},
|
93 |
|
|
{-0.5f, SQ2/4, 0.0f},
|
94 |
8499ba3d
|
Leszek Koltunski
|
{ 0.0f,-SQ2/4, 0.5f},
|
95 |
b9ee3f6e
|
Leszek Koltunski
|
{ 0.5f,-SQ2/4, 0.0f},
|
96 |
|
|
{ 0.0f,-SQ2/4,-0.5f},
|
97 |
8499ba3d
|
Leszek Koltunski
|
{-0.5f,-SQ2/4, 0.0f}
|
98 |
739a64d4
|
Leszek Koltunski
|
};
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102 |
|
|
|
103 |
|
|
float[][] getCuts()
|
104 |
|
|
{
|
105 |
|
|
float[] cut = { 0.0f };
|
106 |
|
|
return new float[][] { cut,cut,cut,cut };
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110 |
|
|
|
111 |
|
|
boolean[][] getRotatable()
|
112 |
|
|
{
|
113 |
|
|
boolean[] tmp = new boolean[] {false,true};
|
114 |
|
|
return new boolean[][] { tmp,tmp,tmp,tmp };
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
118 |
|
|
// specifically for the tablebase
|
119 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120 |
|
|
|
121 |
|
|
int getSize()
|
122 |
|
|
{
|
123 |
|
|
return 138240; // see https://www.jaapsch.net/puzzles/diamond.htm
|
124 |
|
|
}
|
125 |
|
|
|
126 |
c0266cb1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
127 |
|
|
|
128 |
884b702b
|
Leszek Koltunski
|
int getMinScramble()
|
129 |
c0266cb1
|
Leszek Koltunski
|
{
|
130 |
|
|
return 8;
|
131 |
|
|
}
|
132 |
|
|
|
133 |
522d858e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
134 |
|
|
|
135 |
|
|
private int computeCenterQuat(int originalLocation, int newLocation)
|
136 |
|
|
{
|
137 |
4fc4e364
|
Leszek Koltunski
|
return FREE_CENTER[originalLocation][newLocation][0];
|
138 |
522d858e
|
Leszek Koltunski
|
}
|
139 |
|
|
|
140 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
141 |
|
|
|
142 |
4fc4e364
|
Leszek Koltunski
|
private void computeCenterPerm(int[] output, int q0, int q1, int q2, int q3)
|
143 |
522d858e
|
Leszek Koltunski
|
{
|
144 |
4fc4e364
|
Leszek Koltunski
|
for(int j=0; j<4; j++)
|
145 |
|
|
{
|
146 |
|
|
int[] q = FREE_CENTER[0][j];
|
147 |
|
|
if( q[0]==q0 || q[1]==q0 || q[2]==q0 ) { output[0]=j; break; }
|
148 |
|
|
}
|
149 |
|
|
for(int j=0; j<4; j++)
|
150 |
|
|
{
|
151 |
|
|
int[] q = FREE_CENTER[1][j];
|
152 |
|
|
if( q[0]==q1 || q[1]==q1 || q[2]==q1 ) { output[1]=j; break; }
|
153 |
|
|
}
|
154 |
|
|
for(int j=0; j<4; j++)
|
155 |
|
|
{
|
156 |
|
|
int[] q = FREE_CENTER[2][j];
|
157 |
|
|
if( q[0]==q2 || q[1]==q2 || q[2]==q2 ) { output[2]=j; break; }
|
158 |
|
|
}
|
159 |
|
|
for(int j=0; j<4; j++)
|
160 |
|
|
{
|
161 |
|
|
int[] q = FREE_CENTER[3][j];
|
162 |
|
|
if( q[0]==q3 || q[1]==q3 || q[2]==q3 ) { output[3]=j; break; }
|
163 |
|
|
}
|
164 |
522d858e
|
Leszek Koltunski
|
}
|
165 |
|
|
|
166 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
167 |
|
|
|
168 |
4fc4e364
|
Leszek Koltunski
|
private int computeCornerQuat(int originalLocation, int newLocation, int twist)
|
169 |
522d858e
|
Leszek Koltunski
|
{
|
170 |
59d4ca91
|
Leszek Koltunski
|
return CORNER_QUATS[originalLocation][newLocation][twist];
|
171 |
522d858e
|
Leszek Koltunski
|
}
|
172 |
|
|
|
173 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174 |
|
|
|
175 |
|
|
private int computeCornerPerm(int[] output, int[] quats)
|
176 |
|
|
{
|
177 |
4fc4e364
|
Leszek Koltunski
|
int totalTwist = 0;
|
178 |
|
|
|
179 |
|
|
for(int i=0; i<6; i++)
|
180 |
|
|
{
|
181 |
|
|
int q = quats[i];
|
182 |
59d4ca91
|
Leszek Koltunski
|
int[][] perm = CORNER_QUATS[i];
|
183 |
4fc4e364
|
Leszek Koltunski
|
|
184 |
|
|
for(int j=0; j<6; j++)
|
185 |
|
|
{
|
186 |
|
|
int[] p = perm[j];
|
187 |
|
|
|
188 |
8499ba3d
|
Leszek Koltunski
|
if( p[0]==q ) { output[i]=j; break; }
|
189 |
|
|
if( p[1]==q ) { output[i]=j; if( i<5 ) totalTwist+=(1<<i); break; }
|
190 |
4fc4e364
|
Leszek Koltunski
|
}
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
return totalTwist;
|
194 |
522d858e
|
Leszek Koltunski
|
}
|
195 |
|
|
|
196 |
739a64d4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
197 |
|
|
|
198 |
|
|
public int[] getQuats(int index)
|
199 |
|
|
{
|
200 |
522d858e
|
Leszek Koltunski
|
int centers_perm_num = (index%12);
|
201 |
|
|
index /= 12;
|
202 |
8499ba3d
|
Leszek Koltunski
|
int totalTwist = (index%32);
|
203 |
|
|
int corners_perm_num = (index/32);
|
204 |
|
|
|
205 |
522d858e
|
Leszek Koltunski
|
int[] centers_perm = new int[4];
|
206 |
|
|
TablebaseHelpers.getEvenPermutationFromNum(centers_perm,centers_perm_num);
|
207 |
|
|
int[] corners_perm = new int[6];
|
208 |
|
|
TablebaseHelpers.getEvenPermutationFromNum(corners_perm,corners_perm_num);
|
209 |
|
|
|
210 |
|
|
int[] quats = new int[14];
|
211 |
|
|
|
212 |
|
|
for(int i=0; i<6; i++)
|
213 |
|
|
{
|
214 |
|
|
int twist = (totalTwist%2);
|
215 |
|
|
totalTwist /= 2;
|
216 |
|
|
quats[i] = computeCornerQuat(i,corners_perm[i],twist);
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
quats[ 6] = computeCenterQuat(0,centers_perm[0]);
|
220 |
|
|
quats[ 8] = computeCenterQuat(1,centers_perm[1]);
|
221 |
|
|
quats[11] = computeCenterQuat(2,centers_perm[2]);
|
222 |
|
|
quats[13] = computeCenterQuat(3,centers_perm[3]);
|
223 |
|
|
|
224 |
|
|
return quats;
|
225 |
739a64d4
|
Leszek Koltunski
|
}
|
226 |
|
|
|
227 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
228 |
|
|
|
229 |
|
|
public int getIndex(int[] quats)
|
230 |
|
|
{
|
231 |
4fc4e364
|
Leszek Koltunski
|
int[] center_perm = new int[4];
|
232 |
|
|
computeCenterPerm(center_perm, quats[6],quats[8],quats[11],quats[13]);
|
233 |
522d858e
|
Leszek Koltunski
|
int centers_perm_num = TablebaseHelpers.computeEvenPermutationNum(center_perm);
|
234 |
|
|
int[] corners_perm = new int[6];
|
235 |
|
|
int totalTwist = computeCornerPerm(corners_perm,quats);
|
236 |
|
|
int corners_perm_num = TablebaseHelpers.computeEvenPermutationNum(corners_perm);
|
237 |
|
|
|
238 |
4fc4e364
|
Leszek Koltunski
|
return centers_perm_num + 12*(totalTwist + 32*corners_perm_num);
|
239 |
739a64d4
|
Leszek Koltunski
|
}
|
240 |
|
|
}
|