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