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