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