1 |
18354673
|
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.solvers;
|
11 |
|
|
|
12 |
4f2ad167
|
leszek
|
import static org.distorted.objectlib.tablebases.TBSkewb.FIXED;
|
13 |
b4f45fdc
|
Leszek Koltunski
|
import static org.distorted.objectlib.tablebases.TBSkewb.FREE;
|
14 |
|
|
|
15 |
18354673
|
Leszek Koltunski
|
import android.content.res.Resources;
|
16 |
|
|
|
17 |
|
|
import org.distorted.main.R;
|
18 |
da57afae
|
Leszek Koltunski
|
import org.distorted.objectlib.helpers.OperatingSystemInterface;
|
19 |
eb9263dd
|
leszek
|
import org.distorted.objectlib.metadata.ListObjects;
|
20 |
18354673
|
Leszek Koltunski
|
import org.distorted.objectlib.main.TwistyObject;
|
21 |
|
|
import org.distorted.objectlib.tablebases.ImplementedTablebasesList;
|
22 |
c76be0a6
|
Leszek Koltunski
|
import org.distorted.objectlib.tablebases.TBSkewb;
|
23 |
cff92952
|
Leszek Koltunski
|
import org.distorted.objectlib.tablebases.TablebaseHelpers;
|
24 |
18354673
|
Leszek Koltunski
|
import org.distorted.objectlib.tablebases.TablebasesAbstract;
|
25 |
|
|
|
26 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
27 |
|
|
|
28 |
|
|
public class SolverSkewb extends SolverTablebase
|
29 |
|
|
{
|
30 |
|
|
private static final int ERROR_CORNER_135_MISSING = -1;
|
31 |
|
|
private static final int ERROR_CORNER_134_MISSING = -2;
|
32 |
|
|
private static final int ERROR_CORNER_125_MISSING = -3;
|
33 |
|
|
private static final int ERROR_CORNER_124_MISSING = -4;
|
34 |
|
|
private static final int ERROR_CORNER_035_MISSING = -5;
|
35 |
|
|
private static final int ERROR_CORNER_034_MISSING = -6;
|
36 |
|
|
private static final int ERROR_CORNER_025_MISSING = -7;
|
37 |
|
|
private static final int ERROR_CORNER_024_MISSING = -8;
|
38 |
|
|
|
39 |
|
|
private static final int ERROR_CENTER_0_MISSING = -9;
|
40 |
|
|
private static final int ERROR_CENTER_1_MISSING = -10;
|
41 |
|
|
private static final int ERROR_CENTER_2_MISSING = -11;
|
42 |
|
|
private static final int ERROR_CENTER_3_MISSING = -12;
|
43 |
|
|
private static final int ERROR_CENTER_4_MISSING = -13;
|
44 |
|
|
private static final int ERROR_CENTER_5_MISSING = -14;
|
45 |
|
|
|
46 |
|
|
private static final int ERROR_CORNERS_CANNOT = -15;
|
47 |
|
|
private static final int ERROR_CORNER_TWISTED = -16;
|
48 |
|
|
private static final int ERROR_TWO_CENTERS = -17;
|
49 |
|
|
private static final int ERROR_TWO_CORNERS = -18;
|
50 |
|
|
|
51 |
4f2ad167
|
leszek
|
private static final int ERROR_FREE_CORNERS_NOT_EVEN = -19;
|
52 |
|
|
private static final int ERROR_FREE_CORNERS_ROTATED = -20;
|
53 |
|
|
|
54 |
18354673
|
Leszek Koltunski
|
private TablebasesAbstract mSolver;
|
55 |
cff92952
|
Leszek Koltunski
|
private final int[] mFaceColors;
|
56 |
18354673
|
Leszek Koltunski
|
|
57 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
|
59 |
da57afae
|
Leszek Koltunski
|
public SolverSkewb(OperatingSystemInterface os, Resources res, TwistyObject object)
|
60 |
18354673
|
Leszek Koltunski
|
{
|
61 |
da57afae
|
Leszek Koltunski
|
super(os,res,object);
|
62 |
cff92952
|
Leszek Koltunski
|
mFaceColors = new int[6];
|
63 |
18354673
|
Leszek Koltunski
|
}
|
64 |
|
|
|
65 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66 |
|
|
|
67 |
|
|
private void getCorners(TwistyObject object, int[][] corners)
|
68 |
|
|
{
|
69 |
cff92952
|
Leszek Koltunski
|
for(int i=0; i<8; i++)
|
70 |
|
|
for(int j=0; j<3; j++)
|
71 |
|
|
corners[i][j] = object.getCubitFaceStickerIndex(i,j);
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75 |
|
|
|
76 |
4f2ad167
|
leszek
|
private void createCenterPermutation(int[] output, int[] symbols, int[] perm)
|
77 |
|
|
{
|
78 |
|
|
for(int s=0; s<6; s++)
|
79 |
|
|
{
|
80 |
|
|
int symbol = symbols[s];
|
81 |
|
|
|
82 |
|
|
for(int p=0; p<6; p++)
|
83 |
|
|
if( perm[p]==symbol )
|
84 |
|
|
{
|
85 |
|
|
output[s] = p;
|
86 |
|
|
break;
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
92 |
|
|
|
93 |
|
|
private int getCenters(TwistyObject object, int[] out)
|
94 |
cff92952
|
Leszek Koltunski
|
{
|
95 |
6a64512e
|
Leszek Koltunski
|
final int[] map = {4,5,2,3,0,1};
|
96 |
4f2ad167
|
leszek
|
int[] tmp = new int[6];
|
97 |
|
|
int[] mcl = new int[6];
|
98 |
6a64512e
|
Leszek Koltunski
|
boolean[] present = new boolean[6];
|
99 |
18354673
|
Leszek Koltunski
|
|
100 |
cff92952
|
Leszek Koltunski
|
for(int i=0; i<6; i++)
|
101 |
b4f45fdc
|
Leszek Koltunski
|
{
|
102 |
|
|
int color = object.getCubitFaceStickerIndex(i+8,0) - 6;
|
103 |
6a64512e
|
Leszek Koltunski
|
present[color] = true;
|
104 |
4f2ad167
|
leszek
|
tmp[i] = color;
|
105 |
b4f45fdc
|
Leszek Koltunski
|
}
|
106 |
|
|
|
107 |
6a64512e
|
Leszek Koltunski
|
if( !present[0] ) return ERROR_CENTER_0_MISSING;
|
108 |
|
|
if( !present[1] ) return ERROR_CENTER_1_MISSING;
|
109 |
|
|
if( !present[2] ) return ERROR_CENTER_2_MISSING;
|
110 |
|
|
if( !present[3] ) return ERROR_CENTER_3_MISSING;
|
111 |
|
|
if( !present[4] ) return ERROR_CENTER_4_MISSING;
|
112 |
|
|
if( !present[5] ) return ERROR_CENTER_5_MISSING;
|
113 |
|
|
|
114 |
4f2ad167
|
leszek
|
for(int i=0; i<6; i++) mcl[i] = map[mFaceColors[i]];
|
115 |
|
|
createCenterPermutation(out,mcl,tmp);
|
116 |
|
|
|
117 |
6a64512e
|
Leszek Koltunski
|
return 0;
|
118 |
18354673
|
Leszek Koltunski
|
}
|
119 |
|
|
|
120 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
121 |
|
|
|
122 |
cff92952
|
Leszek Koltunski
|
private int commonCornerColor(int[] c1, int[] c2)
|
123 |
18354673
|
Leszek Koltunski
|
{
|
124 |
cff92952
|
Leszek Koltunski
|
int theSame = 0;
|
125 |
|
|
int index = 0;
|
126 |
|
|
|
127 |
|
|
for(int i=0; i<3; i++)
|
128 |
|
|
for(int j=0; j<3; j++)
|
129 |
|
|
if( c1[i]==c2[j] )
|
130 |
|
|
{
|
131 |
|
|
index = i;
|
132 |
|
|
theSame++;
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
return theSame==1 ? c1[index] : ERROR_CORNERS_CANNOT;
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
139 |
|
|
|
140 |
|
|
private int computeFaceColors(int[][] corners, int[] output)
|
141 |
|
|
{
|
142 |
6a64512e
|
Leszek Koltunski
|
final int[][] corner_indices = { {0,3},{5,6},{0,5},{6,3},{0,6},{3,5} };
|
143 |
cff92952
|
Leszek Koltunski
|
|
144 |
|
|
for(int i=0; i<6; i++)
|
145 |
|
|
{
|
146 |
6a64512e
|
Leszek Koltunski
|
int c1 = corner_indices[i][0];
|
147 |
|
|
int c2 = corner_indices[i][1];
|
148 |
cff92952
|
Leszek Koltunski
|
output[i] = commonCornerColor(corners[c1],corners[c2]);
|
149 |
|
|
if( output[i]<0 ) return ERROR_CORNERS_CANNOT;
|
150 |
|
|
}
|
151 |
|
|
|
152 |
18354673
|
Leszek Koltunski
|
return 0;
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
156 |
|
|
|
157 |
6a64512e
|
Leszek Koltunski
|
private boolean cornerIs(int[] corner, int f0, int f1, int f2)
|
158 |
18354673
|
Leszek Koltunski
|
{
|
159 |
6a64512e
|
Leszek Koltunski
|
int c0 = mFaceColors[f0];
|
160 |
|
|
int c1 = mFaceColors[f1];
|
161 |
|
|
int c2 = mFaceColors[f2];
|
162 |
|
|
|
163 |
cff92952
|
Leszek Koltunski
|
return ( (corner[0]==c0 && corner[1]==c1 && corner[2]==c2 ) ||
|
164 |
|
|
(corner[1]==c0 && corner[2]==c1 && corner[0]==c2 ) ||
|
165 |
|
|
(corner[2]==c0 && corner[0]==c1 && corner[1]==c2 ) );
|
166 |
18354673
|
Leszek Koltunski
|
}
|
167 |
|
|
|
168 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
169 |
|
|
|
170 |
cff92952
|
Leszek Koltunski
|
private int checkAllCornersPresent(int[][] corners)
|
171 |
18354673
|
Leszek Koltunski
|
{
|
172 |
cff92952
|
Leszek Koltunski
|
boolean[] present = new boolean[8];
|
173 |
|
|
|
174 |
|
|
for(int i=0; i<8; i++)
|
175 |
|
|
{
|
176 |
|
|
if( cornerIs(corners[i],4,2,0) ) present[0]=true;
|
177 |
|
|
if( cornerIs(corners[i],2,5,0) ) present[1]=true;
|
178 |
|
|
if( cornerIs(corners[i],3,4,0) ) present[2]=true;
|
179 |
|
|
if( cornerIs(corners[i],5,3,0) ) present[3]=true;
|
180 |
|
|
if( cornerIs(corners[i],1,2,4) ) present[4]=true;
|
181 |
|
|
if( cornerIs(corners[i],5,2,1) ) present[5]=true;
|
182 |
|
|
if( cornerIs(corners[i],4,3,1) ) present[6]=true;
|
183 |
|
|
if( cornerIs(corners[i],1,3,5) ) present[7]=true;
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
if( !present[0] ) return ERROR_CORNER_024_MISSING;
|
187 |
|
|
if( !present[1] ) return ERROR_CORNER_025_MISSING;
|
188 |
|
|
if( !present[2] ) return ERROR_CORNER_034_MISSING;
|
189 |
|
|
if( !present[3] ) return ERROR_CORNER_035_MISSING;
|
190 |
|
|
if( !present[4] ) return ERROR_CORNER_124_MISSING;
|
191 |
|
|
if( !present[5] ) return ERROR_CORNER_125_MISSING;
|
192 |
|
|
if( !present[6] ) return ERROR_CORNER_134_MISSING;
|
193 |
|
|
if( !present[7] ) return ERROR_CORNER_135_MISSING;
|
194 |
18354673
|
Leszek Koltunski
|
|
195 |
cff92952
|
Leszek Koltunski
|
return 0;
|
196 |
18354673
|
Leszek Koltunski
|
}
|
197 |
|
|
|
198 |
cff92952
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
199 |
|
|
|
200 |
14cf0761
|
Leszek Koltunski
|
private int retFreeCornerPermutation(int[] perm, int[][] corners)
|
201 |
cff92952
|
Leszek Koltunski
|
{
|
202 |
14cf0761
|
Leszek Koltunski
|
perm[0] = -1;
|
203 |
cff92952
|
Leszek Koltunski
|
perm[1] = -1;
|
204 |
|
|
perm[2] = -1;
|
205 |
14cf0761
|
Leszek Koltunski
|
perm[3] = -1;
|
206 |
cff92952
|
Leszek Koltunski
|
|
207 |
|
|
for(int i=0; i<4; i++)
|
208 |
|
|
{
|
209 |
b4f45fdc
|
Leszek Koltunski
|
int[] cor = corners[FREE[i]];
|
210 |
cff92952
|
Leszek Koltunski
|
|
211 |
14cf0761
|
Leszek Koltunski
|
if( cornerIs(cor,2,5,0) ) perm[0] = i;
|
212 |
|
|
if( cornerIs(cor,3,4,0) ) perm[1] = i;
|
213 |
|
|
if( cornerIs(cor,1,2,4) ) perm[2] = i;
|
214 |
|
|
if( cornerIs(cor,1,3,5) ) perm[3] = i;
|
215 |
cff92952
|
Leszek Koltunski
|
}
|
216 |
|
|
|
217 |
14cf0761
|
Leszek Koltunski
|
if( perm[0]==-1 ) return ERROR_CORNER_025_MISSING;
|
218 |
|
|
if( perm[1]==-1 ) return ERROR_CORNER_034_MISSING;
|
219 |
|
|
if( perm[2]==-1 ) return ERROR_CORNER_124_MISSING;
|
220 |
|
|
if( perm[3]==-1 ) return ERROR_CORNER_135_MISSING;
|
221 |
cff92952
|
Leszek Koltunski
|
|
222 |
18354673
|
Leszek Koltunski
|
return 0;
|
223 |
|
|
}
|
224 |
|
|
|
225 |
14cf0761
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
226 |
cff92952
|
Leszek Koltunski
|
|
227 |
14cf0761
|
Leszek Koltunski
|
private void computeCornerQuats(int[] quats, int[][] corners, int[] perm)
|
228 |
|
|
{
|
229 |
6a64512e
|
Leszek Koltunski
|
final int[] zeroeth_face_map = { 4,2,3,5,1,5,4,1 };
|
230 |
b4f45fdc
|
Leszek Koltunski
|
int[] twist = new int[8];
|
231 |
cff92952
|
Leszek Koltunski
|
|
232 |
4f2ad167
|
leszek
|
for(int i=0; i<4; i++)
|
233 |
cff92952
|
Leszek Koltunski
|
{
|
234 |
4f2ad167
|
leszek
|
int fi = FIXED[i];
|
235 |
|
|
int colorFi = mFaceColors[zeroeth_face_map[fi]];
|
236 |
|
|
int[] cFi = corners[fi];
|
237 |
14cf0761
|
Leszek Koltunski
|
|
238 |
4f2ad167
|
leszek
|
if( cFi[0]==colorFi ) twist[fi] = 0;
|
239 |
|
|
else if( cFi[1]==colorFi ) twist[fi] = 1;
|
240 |
|
|
else twist[fi] = 2;
|
241 |
cff92952
|
Leszek Koltunski
|
}
|
242 |
|
|
|
243 |
4f2ad167
|
leszek
|
int[] inv_perm = new int[4];
|
244 |
|
|
TablebaseHelpers.invertPermutation(perm,inv_perm);
|
245 |
|
|
|
246 |
|
|
int common14 = commonCornerColor(corners[1], corners[4]);
|
247 |
|
|
int common27 = commonCornerColor(corners[2], corners[7]);
|
248 |
|
|
int common47 = commonCornerColor(corners[4], corners[7]);
|
249 |
|
|
int index;
|
250 |
|
|
int[] c;
|
251 |
|
|
|
252 |
|
|
index = FREE[inv_perm[0]];
|
253 |
|
|
c = corners[FREE[0]];
|
254 |
|
|
|
255 |
|
|
if(c[0]==common14) twist[index] = 0;
|
256 |
|
|
else if(c[1]==common14) twist[index] = 2;
|
257 |
|
|
else twist[index] = 1;
|
258 |
|
|
|
259 |
|
|
index = FREE[inv_perm[1]];
|
260 |
|
|
c = corners[FREE[1]];
|
261 |
|
|
|
262 |
|
|
if(c[0]==common27) twist[index] = 0;
|
263 |
|
|
else if(c[1]==common27) twist[index] = 2;
|
264 |
|
|
else twist[index] = 1;
|
265 |
|
|
|
266 |
|
|
index = FREE[inv_perm[2]];
|
267 |
|
|
c = corners[FREE[2]];
|
268 |
|
|
|
269 |
|
|
if(c[0]==common47) twist[index] = 0;
|
270 |
|
|
else if(c[1]==common47) twist[index] = 2;
|
271 |
|
|
else twist[index] = 1;
|
272 |
|
|
|
273 |
|
|
index = FREE[inv_perm[3]];
|
274 |
|
|
c = corners[FREE[3]];
|
275 |
|
|
|
276 |
|
|
if(c[0]==common47) twist[index] = 0;
|
277 |
|
|
else if(c[1]==common47) twist[index] = 2;
|
278 |
|
|
else twist[index] = 1;
|
279 |
|
|
|
280 |
b4f45fdc
|
Leszek Koltunski
|
TBSkewb.fillInQuats(quats,perm,twist);
|
281 |
cff92952
|
Leszek Koltunski
|
}
|
282 |
|
|
|
283 |
18354673
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
284 |
|
|
|
285 |
|
|
public int tablebaseIndex(TwistyObject object)
|
286 |
|
|
{
|
287 |
cff92952
|
Leszek Koltunski
|
int[][] corners= new int[8][3];
|
288 |
|
|
int[] centers = new int[6];
|
289 |
|
|
int[] twist = new int[8];
|
290 |
14cf0761
|
Leszek Koltunski
|
int[] freePerm = new int[4];
|
291 |
|
|
int[] quats = new int[8];
|
292 |
18354673
|
Leszek Koltunski
|
|
293 |
|
|
getCorners(object,corners);
|
294 |
|
|
|
295 |
cff92952
|
Leszek Koltunski
|
int result1 = computeFaceColors(corners,mFaceColors);
|
296 |
18354673
|
Leszek Koltunski
|
if( result1<0 ) return result1;
|
297 |
|
|
|
298 |
cff92952
|
Leszek Koltunski
|
int result2 = checkAllCornersPresent(corners);
|
299 |
|
|
if( result2<0 ) return result2;
|
300 |
18354673
|
Leszek Koltunski
|
|
301 |
6a64512e
|
Leszek Koltunski
|
int result3 = getCenters(object,centers);
|
302 |
cff92952
|
Leszek Koltunski
|
if( result3<0 ) return result3;
|
303 |
18354673
|
Leszek Koltunski
|
|
304 |
cff92952
|
Leszek Koltunski
|
if( !TablebaseHelpers.permutationIsEven(centers) ) return ERROR_TWO_CENTERS;
|
305 |
|
|
int center_perm_num = TablebaseHelpers.computeEvenPermutationNum(centers);
|
306 |
18354673
|
Leszek Koltunski
|
|
307 |
14cf0761
|
Leszek Koltunski
|
int result4 = retFreeCornerPermutation(freePerm,corners);
|
308 |
cff92952
|
Leszek Koltunski
|
if( result4<0 ) return result4;
|
309 |
|
|
|
310 |
14cf0761
|
Leszek Koltunski
|
computeCornerQuats(quats,corners,freePerm);
|
311 |
4f2ad167
|
leszek
|
|
312 |
|
|
int[] freeLoc = new int[4];
|
313 |
|
|
for(int f=0; f<4; f++) freeLoc[f] = TBSkewb.computeLocation(f,quats[FREE[f]]);
|
314 |
|
|
if( !TablebaseHelpers.permutationIsEven(freeLoc) ) return ERROR_FREE_CORNERS_NOT_EVEN;
|
315 |
|
|
|
316 |
c76be0a6
|
Leszek Koltunski
|
TBSkewb.computeCornerTwists(twist,quats);
|
317 |
b4f45fdc
|
Leszek Koltunski
|
|
318 |
|
|
int total = 0;
|
319 |
4f2ad167
|
leszek
|
for(int i=0; i<8; i++) total += twist[i];
|
320 |
14cf0761
|
Leszek Koltunski
|
if( (total%3)!=0 ) return ERROR_CORNER_TWISTED;
|
321 |
|
|
int totalTwist = twist[0]+ 3*(twist[1]+ 3*(twist[2]+ 3*(twist[3]+ 3*(twist[4]+ 3*(twist[5]+ 3*twist[6])))));
|
322 |
cff92952
|
Leszek Koltunski
|
|
323 |
4f2ad167
|
leszek
|
int sumFixedTwists = twist[FIXED[0]]+twist[FIXED[1]]+twist[FIXED[2]]+twist[FIXED[3]];
|
324 |
|
|
int freeLoc1 = TBSkewb.permFree1(freeLoc[0],sumFixedTwists);
|
325 |
|
|
if( freeLoc[1] != freeLoc1 ) return ERROR_FREE_CORNERS_ROTATED;
|
326 |
cff92952
|
Leszek Koltunski
|
|
327 |
4f2ad167
|
leszek
|
return center_perm_num+ 360*(totalTwist + 2187*freeLoc[0]);
|
328 |
18354673
|
Leszek Koltunski
|
}
|
329 |
|
|
|
330 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
331 |
|
|
|
332 |
|
|
private int getColorIndex2(int face)
|
333 |
|
|
{
|
334 |
|
|
switch(mFaceColors[face])
|
335 |
|
|
{
|
336 |
|
|
case 0: return R.string.color_yellow2;
|
337 |
|
|
case 1: return R.string.color_white2;
|
338 |
|
|
case 2: return R.string.color_blue2;
|
339 |
|
|
case 3: return R.string.color_green2;
|
340 |
|
|
case 4: return R.string.color_red2;
|
341 |
|
|
case 5: return R.string.color_orange2;
|
342 |
|
|
}
|
343 |
|
|
|
344 |
|
|
return -1;
|
345 |
|
|
}
|
346 |
|
|
|
347 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
348 |
|
|
|
349 |
|
|
private int getColorIndex3(int face)
|
350 |
|
|
{
|
351 |
|
|
switch(mFaceColors[face])
|
352 |
|
|
{
|
353 |
|
|
case 0: return R.string.color_yellow3;
|
354 |
|
|
case 1: return R.string.color_white3;
|
355 |
|
|
case 2: return R.string.color_blue3;
|
356 |
|
|
case 3: return R.string.color_green3;
|
357 |
|
|
case 4: return R.string.color_red3;
|
358 |
|
|
case 5: return R.string.color_orange3;
|
359 |
|
|
}
|
360 |
|
|
|
361 |
|
|
return -1;
|
362 |
|
|
}
|
363 |
|
|
|
364 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
365 |
|
|
|
366 |
|
|
private int getColorIndex4(int face)
|
367 |
|
|
{
|
368 |
|
|
switch(mFaceColors[face])
|
369 |
|
|
{
|
370 |
|
|
case 0: return R.string.color_yellow4;
|
371 |
|
|
case 1: return R.string.color_white4;
|
372 |
|
|
case 2: return R.string.color_blue4;
|
373 |
|
|
case 3: return R.string.color_green4;
|
374 |
|
|
case 4: return R.string.color_red4;
|
375 |
|
|
case 5: return R.string.color_orange4;
|
376 |
|
|
}
|
377 |
|
|
|
378 |
|
|
return -1;
|
379 |
|
|
}
|
380 |
|
|
|
381 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
382 |
|
|
|
383 |
|
|
private String cornerError(Resources res, int face0, int face1, int face2)
|
384 |
|
|
{
|
385 |
|
|
int j0 = getColorIndex3(face0);
|
386 |
|
|
int j1 = getColorIndex3(face1);
|
387 |
|
|
int j2 = getColorIndex4(face2);
|
388 |
|
|
|
389 |
|
|
String c0 = res.getString(j0);
|
390 |
|
|
String c1 = res.getString(j1);
|
391 |
|
|
String c2 = res.getString(j2);
|
392 |
|
|
|
393 |
|
|
return res.getString(R.string.solver_generic_missing_corner,c0,c1,c2);
|
394 |
|
|
}
|
395 |
|
|
|
396 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
397 |
|
|
|
398 |
|
|
private String centerError(Resources res, int face)
|
399 |
|
|
{
|
400 |
|
|
int color = getColorIndex2(face);
|
401 |
|
|
String clr= res.getString(color);
|
402 |
|
|
return res.getString(R.string.solver_generic_missing_center,clr);
|
403 |
|
|
}
|
404 |
|
|
|
405 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
406 |
|
|
|
407 |
|
|
public String error(int index, Resources res)
|
408 |
|
|
{
|
409 |
|
|
switch(index)
|
410 |
|
|
{
|
411 |
4f2ad167
|
leszek
|
case ERROR_CORNER_135_MISSING : return cornerError(res,1,3,5);
|
412 |
|
|
case ERROR_CORNER_134_MISSING : return cornerError(res,1,3,4);
|
413 |
|
|
case ERROR_CORNER_125_MISSING : return cornerError(res,1,2,5);
|
414 |
|
|
case ERROR_CORNER_124_MISSING : return cornerError(res,1,2,4);
|
415 |
|
|
case ERROR_CORNER_035_MISSING : return cornerError(res,0,3,5);
|
416 |
|
|
case ERROR_CORNER_034_MISSING : return cornerError(res,0,3,4);
|
417 |
|
|
case ERROR_CORNER_025_MISSING : return cornerError(res,0,2,5);
|
418 |
|
|
case ERROR_CORNER_024_MISSING : return cornerError(res,0,2,4);
|
419 |
|
|
|
420 |
|
|
case ERROR_CENTER_0_MISSING : return centerError(res,0);
|
421 |
|
|
case ERROR_CENTER_1_MISSING : return centerError(res,1);
|
422 |
|
|
case ERROR_CENTER_2_MISSING : return centerError(res,2);
|
423 |
|
|
case ERROR_CENTER_3_MISSING : return centerError(res,3);
|
424 |
|
|
case ERROR_CENTER_4_MISSING : return centerError(res,4);
|
425 |
|
|
case ERROR_CENTER_5_MISSING : return centerError(res,5);
|
426 |
|
|
|
427 |
|
|
case ERROR_CORNERS_CANNOT : return res.getString(R.string.solver_generic_corners_cannot);
|
428 |
|
|
case ERROR_CORNER_TWISTED : return res.getString(R.string.solver_generic_corner_twist);
|
429 |
|
|
case ERROR_TWO_CENTERS : return res.getString(R.string.solver_generic_two_centers);
|
430 |
|
|
case ERROR_TWO_CORNERS : return res.getString(R.string.solver_generic_two_corners);
|
431 |
|
|
|
432 |
|
|
case ERROR_FREE_CORNERS_NOT_EVEN: return res.getString(R.string.solver_generic_free_corners_odd);
|
433 |
|
|
case ERROR_FREE_CORNERS_ROTATED : return res.getString(R.string.solver_generic_free_corners_rotated);
|
434 |
18354673
|
Leszek Koltunski
|
}
|
435 |
|
|
|
436 |
|
|
return null;
|
437 |
|
|
}
|
438 |
|
|
|
439 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
440 |
|
|
|
441 |
da57afae
|
Leszek Koltunski
|
public int[][] solution(int index, OperatingSystemInterface os)
|
442 |
18354673
|
Leszek Koltunski
|
{
|
443 |
|
|
if( mSolver==null )
|
444 |
|
|
{
|
445 |
eb9263dd
|
leszek
|
mSolver = ImplementedTablebasesList.createPacked(os, ListObjects.SKEW_2.name() );
|
446 |
18354673
|
Leszek Koltunski
|
}
|
447 |
|
|
|
448 |
bdcf2372
|
Leszek Koltunski
|
return mSolver!=null ? mSolver.solution(index,null,os) : null;
|
449 |
18354673
|
Leszek Koltunski
|
}
|
450 |
|
|
}
|