1 |
786cb5f5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
ccd8a6f2
|
Leszek Koltunski
|
import static org.distorted.objectlib.main.TwistyObject.SQ3;
|
16 |
786cb5f5
|
Leszek Koltunski
|
|
17 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
18 |
|
|
|
19 |
a8d83300
|
Leszek Koltunski
|
public class TBIvyCube extends TablebasesAbstract
|
20 |
786cb5f5
|
Leszek Koltunski
|
{
|
21 |
f9980f6a
|
Leszek Koltunski
|
private static final int[] mTmp = new int[6];
|
22 |
|
|
|
23 |
|
|
private static final int[][] MAP = { {0,4,2,2,5,3,4,5,3,0,1,1},
|
24 |
|
|
{1,5,3,3,4,2,5,4,2,1,0,0},
|
25 |
|
|
{2,0,4,5,0,5,1,1,4,3,3,2},
|
26 |
|
|
{3,1,5,4,1,4,0,0,5,2,2,3},
|
27 |
|
|
{4,2,0,1,3,0,3,2,1,5,4,5},
|
28 |
|
|
{5,3,1,0,2,1,2,3,0,4,5,4} };
|
29 |
|
|
|
30 |
786cb5f5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31 |
|
|
|
32 |
a8d83300
|
Leszek Koltunski
|
public TBIvyCube()
|
33 |
786cb5f5
|
Leszek Koltunski
|
{
|
34 |
|
|
super();
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38 |
|
|
|
39 |
a8d83300
|
Leszek Koltunski
|
public TBIvyCube(Resources res)
|
40 |
786cb5f5
|
Leszek Koltunski
|
{
|
41 |
f9980f6a
|
Leszek Koltunski
|
super(res,org.distorted.objectlib.R.raw.ivy_2_tablebase);
|
42 |
786cb5f5
|
Leszek Koltunski
|
}
|
43 |
|
|
|
44 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45 |
|
|
|
46 |
|
|
int[][] getBasicAngles()
|
47 |
|
|
{
|
48 |
|
|
int[] tmp = {3,3};
|
49 |
|
|
return new int[][] { tmp,tmp,tmp,tmp };
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53 |
|
|
|
54 |
|
|
Static3D[] getRotationAxis()
|
55 |
|
|
{
|
56 |
ccd8a6f2
|
Leszek Koltunski
|
return new Static3D[]
|
57 |
|
|
{
|
58 |
|
|
new Static3D( SQ3/3, SQ3/3, SQ3/3),
|
59 |
|
|
new Static3D( SQ3/3, SQ3/3,-SQ3/3),
|
60 |
|
|
new Static3D( SQ3/3,-SQ3/3, SQ3/3),
|
61 |
|
|
new Static3D( SQ3/3,-SQ3/3,-SQ3/3)
|
62 |
|
|
};
|
63 |
786cb5f5
|
Leszek Koltunski
|
}
|
64 |
|
|
|
65 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66 |
|
|
|
67 |
|
|
float[][] getPosition()
|
68 |
|
|
{
|
69 |
|
|
final float DIST_CORNER = 1;
|
70 |
|
|
final float DIST_CENTER = 1;
|
71 |
|
|
|
72 |
|
|
return new float[][]
|
73 |
|
|
{
|
74 |
|
|
{ DIST_CORNER, DIST_CORNER, DIST_CORNER },
|
75 |
|
|
{-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
|
76 |
|
|
{-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
|
77 |
|
|
{ DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
|
78 |
|
|
{ DIST_CENTER, 0, 0 },
|
79 |
|
|
{-DIST_CENTER, 0, 0 },
|
80 |
f9980f6a
|
Leszek Koltunski
|
{ 0, DIST_CENTER, 0 },
|
81 |
|
|
{ 0,-DIST_CENTER, 0 },
|
82 |
|
|
{ 0, 0, DIST_CENTER },
|
83 |
|
|
{ 0, 0,-DIST_CENTER },
|
84 |
786cb5f5
|
Leszek Koltunski
|
};
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88 |
|
|
|
89 |
|
|
float[][] getCuts()
|
90 |
|
|
{
|
91 |
|
|
float[] cut = { 0.0f };
|
92 |
|
|
return new float[][] { cut,cut,cut,cut };
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96 |
|
|
|
97 |
|
|
boolean[][] getRotatable()
|
98 |
|
|
{
|
99 |
f9980f6a
|
Leszek Koltunski
|
boolean[] tmp1 = new boolean[] {false,true};
|
100 |
|
|
boolean[] tmp2 = new boolean[] {true,false};
|
101 |
|
|
|
102 |
|
|
return new boolean[][] { tmp1,tmp2,tmp2,tmp1 };
|
103 |
786cb5f5
|
Leszek Koltunski
|
}
|
104 |
|
|
|
105 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106 |
|
|
// specifically for the tablebase
|
107 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108 |
|
|
// orientations of 4 corners + any even permutation of 6 centers
|
109 |
|
|
|
110 |
|
|
int getSize()
|
111 |
|
|
{
|
112 |
|
|
return (3*3*3*3)*(6*5*4*3);
|
113 |
|
|
}
|
114 |
|
|
|
115 |
c0266cb1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
116 |
|
|
|
117 |
884b702b
|
Leszek Koltunski
|
int getMinScramble()
|
118 |
c0266cb1
|
Leszek Koltunski
|
{
|
119 |
|
|
return 7;
|
120 |
|
|
}
|
121 |
|
|
|
122 |
786cb5f5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123 |
|
|
|
124 |
f9980f6a
|
Leszek Koltunski
|
private int findFirst(int[] table, int value)
|
125 |
|
|
{
|
126 |
|
|
int len = table.length;
|
127 |
|
|
|
128 |
|
|
for(int i=0; i<len; i++)
|
129 |
|
|
if( table[i]==value ) return i;
|
130 |
|
|
|
131 |
|
|
return -1;
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135 |
|
|
|
136 |
|
|
public int[] getQuats(int index)
|
137 |
786cb5f5
|
Leszek Koltunski
|
{
|
138 |
f9980f6a
|
Leszek Koltunski
|
int perm_num = index%360;
|
139 |
|
|
index /= 360;
|
140 |
|
|
int twist0 = index%3;
|
141 |
|
|
index /= 3;
|
142 |
|
|
int twist1 = index%3;
|
143 |
|
|
index /= 3;
|
144 |
|
|
int twist2 = index%3;
|
145 |
|
|
index /= 3;
|
146 |
|
|
int twist3 = index%3;
|
147 |
|
|
|
148 |
|
|
int[] ret = new int[10];
|
149 |
|
|
|
150 |
|
|
ret[0] = twist0==0 ? 0 : (twist0==1 ? 2:1);
|
151 |
|
|
ret[1] = twist1==0 ? 0 : (twist1==1 ? 5:6);
|
152 |
|
|
ret[2] = twist2==0 ? 0 : (twist2==1 ? 3:4);
|
153 |
|
|
ret[3] = twist3==0 ? 0 : (twist3==1 ? 8:7);
|
154 |
|
|
|
155 |
522d858e
|
Leszek Koltunski
|
TablebaseHelpers.getEvenPermutationFromNum(mTmp,perm_num);
|
156 |
f9980f6a
|
Leszek Koltunski
|
|
157 |
|
|
for(int i=0; i<6; i++)
|
158 |
|
|
{
|
159 |
|
|
int cubitThatMoves = mTmp[i];
|
160 |
|
|
ret[cubitThatMoves+4] = findFirst(MAP[cubitThatMoves],i);
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
return ret;
|
164 |
786cb5f5
|
Leszek Koltunski
|
}
|
165 |
|
|
|
166 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
167 |
|
|
|
168 |
f9980f6a
|
Leszek Koltunski
|
public int getIndex(int[] quats)
|
169 |
786cb5f5
|
Leszek Koltunski
|
{
|
170 |
f9980f6a
|
Leszek Koltunski
|
int twist0 = quats[0]==0 ? 0 : (quats[0]==1 ? 2:1);
|
171 |
|
|
int twist1 = quats[1]==0 ? 0 : (quats[1]==6 ? 2:1);
|
172 |
|
|
int twist2 = quats[2]==0 ? 0 : (quats[2]==4 ? 2:1);
|
173 |
|
|
int twist3 = quats[3]==0 ? 0 : (quats[3]==7 ? 2:1);
|
174 |
|
|
|
175 |
|
|
int c4 = MAP[0][quats[4]];
|
176 |
|
|
int c5 = MAP[1][quats[5]];
|
177 |
|
|
int c6 = MAP[2][quats[6]];
|
178 |
|
|
int c7 = MAP[3][quats[7]];
|
179 |
|
|
int c8 = MAP[4][quats[8]];
|
180 |
|
|
int c9 = MAP[5][quats[9]];
|
181 |
|
|
|
182 |
|
|
mTmp[c4]=0;
|
183 |
|
|
mTmp[c5]=1;
|
184 |
|
|
mTmp[c6]=2;
|
185 |
|
|
mTmp[c7]=3;
|
186 |
|
|
mTmp[c8]=4;
|
187 |
|
|
mTmp[c9]=5;
|
188 |
|
|
|
189 |
|
|
int perm_num = TablebaseHelpers.computeEvenPermutationNum(mTmp);
|
190 |
|
|
|
191 |
|
|
return perm_num + 360*(twist0+ 3*(twist1+ 3*(twist2+ 3*twist3)));
|
192 |
786cb5f5
|
Leszek Koltunski
|
}
|
193 |
|
|
}
|