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
|
|
14
|
import android.content.res.Resources;
|
15
|
|
16
|
import org.distorted.library.type.Static3D;
|
17
|
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
public class TBPyraminxDiamond extends TablebasesAbstract
|
21
|
{
|
22
|
private static final int[][] CORNER_QUATS =
|
23
|
{
|
24
|
{0,0,0,0},
|
25
|
{0,0,0,0},
|
26
|
{0,0,0,0},
|
27
|
{0,0,0,0},
|
28
|
{0,0,0,0},
|
29
|
{0,0,0,0},
|
30
|
};
|
31
|
|
32
|
private static final int[][] CENTER_QUATS =
|
33
|
{
|
34
|
{0,0,0,0,0,0,0,0},
|
35
|
{0,0,0,0,0,0,0,0},
|
36
|
{0,0,0,0,0,0,0,0},
|
37
|
{0,0,0,0,0,0,0,0},
|
38
|
{0,0,0,0,0,0,0,0},
|
39
|
{0,0,0,0,0,0,0,0},
|
40
|
{0,0,0,0,0,0,0,0},
|
41
|
{0,0,0,0,0,0,0,0},
|
42
|
};
|
43
|
|
44
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45
|
|
46
|
public TBPyraminxDiamond()
|
47
|
{
|
48
|
super();
|
49
|
}
|
50
|
|
51
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
52
|
|
53
|
public TBPyraminxDiamond(Resources res)
|
54
|
{
|
55
|
super(res, 0);
|
56
|
}
|
57
|
|
58
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59
|
|
60
|
int[][] getBasicAngles()
|
61
|
{
|
62
|
int[] tmp = {4,4,4};
|
63
|
return new int[][] { tmp,tmp,tmp };
|
64
|
}
|
65
|
|
66
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67
|
|
68
|
Static3D[] getRotationAxis()
|
69
|
{
|
70
|
return new Static3D[]
|
71
|
{
|
72
|
new Static3D(SQ2/2, 0, SQ2/2),
|
73
|
new Static3D( 0, 1, 0),
|
74
|
new Static3D(SQ2/2, 0,-SQ2/2)
|
75
|
};
|
76
|
}
|
77
|
|
78
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79
|
|
80
|
float[][] getPosition()
|
81
|
{
|
82
|
float B0 = 1.5f*SQ2;
|
83
|
float C0 = 1.5f;
|
84
|
float A = 1.03f;
|
85
|
float B1 = 0.5f*SQ2*A;
|
86
|
float C1 = A;
|
87
|
|
88
|
return new float[][]
|
89
|
{
|
90
|
{ 0, B0, 0 },
|
91
|
{ 0,-B0, 0 },
|
92
|
{ C0, 0, C0 },
|
93
|
{ C0, 0,-C0 },
|
94
|
{-C0, 0, C0 },
|
95
|
{-C0, 0,-C0 },
|
96
|
|
97
|
{ 0, B1, C1 },
|
98
|
{ 0, B1,-C1 },
|
99
|
{ 0,-B1, C1 },
|
100
|
{ 0,-B1,-C1 },
|
101
|
{ C1, B1, 0 },
|
102
|
{ C1,-B1, 0 },
|
103
|
{-C1, B1, 0 },
|
104
|
{-C1,-B1, 0 },
|
105
|
};
|
106
|
}
|
107
|
|
108
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109
|
|
110
|
float[][] getCuts()
|
111
|
{
|
112
|
float C = 0.5f*SQ2;
|
113
|
float[] cut = { -C,C};
|
114
|
return new float[][] { cut,cut,cut };
|
115
|
}
|
116
|
|
117
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
118
|
|
119
|
boolean[][] getRotatable()
|
120
|
{
|
121
|
boolean[] tmp = {true,false,true};
|
122
|
return new boolean[][] { tmp,tmp,tmp };
|
123
|
}
|
124
|
|
125
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
126
|
// specifically for the tablebase
|
127
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128
|
// 4^6 - corner twists; 8! - center permutation; divide by 2 because parity of permutation must
|
129
|
// agree with parity of total twists = (4^6)*8! / 2 = 82.575.360
|
130
|
|
131
|
int getSize()
|
132
|
{
|
133
|
return 82575360;
|
134
|
}
|
135
|
|
136
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
137
|
|
138
|
int getMinScramble()
|
139
|
{
|
140
|
return 8;
|
141
|
}
|
142
|
|
143
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
144
|
|
145
|
private int findIndex(int[] table, int entry)
|
146
|
{
|
147
|
int len = table.length;
|
148
|
|
149
|
for(int i=0; i<len; i++)
|
150
|
if( table[i]==entry ) return i;
|
151
|
|
152
|
return -1;
|
153
|
}
|
154
|
|
155
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
156
|
|
157
|
public int[] getQuats(int index)
|
158
|
{
|
159
|
int[] quats = new int[14];
|
160
|
int[] perm = new int[8];
|
161
|
int[] twist = new int[6];
|
162
|
|
163
|
int centers_perm_num = index/2048;
|
164
|
int total_twist = index%2048;
|
165
|
|
166
|
TablebaseHelpers.getPermutationFromNum(perm,8,centers_perm_num);
|
167
|
boolean even = TablebaseHelpers.permutationIsEven(perm);
|
168
|
|
169
|
for(int i=0; i<5; i++) { twist[i] = total_twist%4; total_twist /=4; }
|
170
|
|
171
|
int total = twist[0]+twist[1]+twist[2]+twist[3]+twist[4]+(even?0:1);
|
172
|
twist[5] = 2*(1-total_twist) + (total%2);
|
173
|
|
174
|
for(int i=0; i<6; i++) quats[i ] = CORNER_QUATS[i][twist[i]];
|
175
|
for(int i=0; i<8; i++) quats[i+6] = CENTER_QUATS[i][perm[i]];
|
176
|
|
177
|
return quats;
|
178
|
}
|
179
|
|
180
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
181
|
|
182
|
public int getIndex(int[] quats)
|
183
|
{
|
184
|
int[] twist = new int[6];
|
185
|
int[] perm = new int[8];
|
186
|
|
187
|
for(int i=0; i<6; i++) twist[i] = findIndex(CORNER_QUATS[i],quats[i]);
|
188
|
for(int i=0; i<8; i++) perm[i] = findIndex(CENTER_QUATS[i],quats[i]);
|
189
|
|
190
|
int centers_perm_num = TablebaseHelpers.computePermutationNum(perm);
|
191
|
int total_twist = twist[0]+ 4*(twist[1]+ 4*(twist[2]+ 4*(twist[3]+ 4*(twist[4]+ 4*(twist[5]>1 ? 0:1)))));
|
192
|
|
193
|
return total_twist + 2048*centers_perm_num;
|
194
|
}
|
195
|
}
|
196
|
|