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