Revision 4f2ad167
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/solvers/SolverSkewb.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.solvers; |
11 | 11 |
|
12 |
import static org.distorted.objectlib.tablebases.TBSkewb.FIXED; |
|
12 | 13 |
import static org.distorted.objectlib.tablebases.TBSkewb.FREE; |
13 | 14 |
|
14 | 15 |
import android.content.res.Resources; |
... | ... | |
47 | 48 |
private static final int ERROR_TWO_CENTERS = -17; |
48 | 49 |
private static final int ERROR_TWO_CORNERS = -18; |
49 | 50 |
|
51 |
private static final int ERROR_FREE_CORNERS_NOT_EVEN = -19; |
|
52 |
private static final int ERROR_FREE_CORNERS_ROTATED = -20; |
|
53 |
|
|
50 | 54 |
private TablebasesAbstract mSolver; |
51 | 55 |
private final int[] mFaceColors; |
52 | 56 |
|
... | ... | |
69 | 73 |
|
70 | 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
71 | 75 |
|
72 |
private int getCenters(TwistyObject object, int[] output) |
|
76 |
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) |
|
73 | 94 |
{ |
74 | 95 |
final int[] map = {4,5,2,3,0,1}; |
75 |
int[] inverted_perm = new int[6]; |
|
96 |
int[] tmp = new int[6]; |
|
97 |
int[] mcl = new int[6]; |
|
76 | 98 |
boolean[] present = new boolean[6]; |
77 | 99 |
|
78 | 100 |
for(int i=0; i<6; i++) |
79 | 101 |
{ |
80 | 102 |
int color = object.getCubitFaceStickerIndex(i+8,0) - 6; |
81 | 103 |
present[color] = true; |
82 |
inverted_perm[i] = map[mFaceColors[color]];
|
|
104 |
tmp[i] = color;
|
|
83 | 105 |
} |
84 | 106 |
|
85 | 107 |
if( !present[0] ) return ERROR_CENTER_0_MISSING; |
... | ... | |
89 | 111 |
if( !present[4] ) return ERROR_CENTER_4_MISSING; |
90 | 112 |
if( !present[5] ) return ERROR_CENTER_5_MISSING; |
91 | 113 |
|
92 |
TablebaseHelpers.invertPermutation(inverted_perm,output); |
|
114 |
for(int i=0; i<6; i++) mcl[i] = map[mFaceColors[i]]; |
|
115 |
createCenterPermutation(out,mcl,tmp); |
|
116 |
|
|
93 | 117 |
return 0; |
94 | 118 |
} |
95 | 119 |
|
... | ... | |
198 | 222 |
return 0; |
199 | 223 |
} |
200 | 224 |
|
201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
202 |
|
|
203 |
private int retCornerPerm(int index, int[] perm) |
|
204 |
{ |
|
205 |
switch(index) |
|
206 |
{ |
|
207 |
case 0: return 0; |
|
208 |
case 1: return FREE[perm[0]]; |
|
209 |
case 2: return FREE[perm[1]]; |
|
210 |
case 3: return 3; |
|
211 |
case 4: return FREE[perm[2]]; |
|
212 |
case 5: return 5; |
|
213 |
case 6: return 6; |
|
214 |
case 7: return FREE[perm[3]]; |
|
215 |
} |
|
216 |
|
|
217 |
return -1; |
|
218 |
} |
|
219 |
|
|
220 | 225 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
221 | 226 |
|
222 | 227 |
private void computeCornerQuats(int[] quats, int[][] corners, int[] perm) |
... | ... | |
224 | 229 |
final int[] zeroeth_face_map = { 4,2,3,5,1,5,4,1 }; |
225 | 230 |
int[] twist = new int[8]; |
226 | 231 |
|
227 |
for(int i=0; i<8; i++)
|
|
232 |
for(int i=0; i<4; i++)
|
|
228 | 233 |
{ |
229 |
int color = mFaceColors[zeroeth_face_map[i]]; |
|
230 |
int[] c = corners[retCornerPerm(i,perm)]; |
|
234 |
int fi = FIXED[i]; |
|
235 |
int colorFi = mFaceColors[zeroeth_face_map[fi]]; |
|
236 |
int[] cFi = corners[fi]; |
|
231 | 237 |
|
232 |
if( c[0]==color ) twist[i] = 0;
|
|
233 |
else if( c[1]==color ) twist[i] = 1;
|
|
234 |
else twist[i] = 2;
|
|
238 |
if( cFi[0]==colorFi ) twist[fi] = 0;
|
|
239 |
else if( cFi[1]==colorFi ) twist[fi] = 1;
|
|
240 |
else twist[fi] = 2;
|
|
235 | 241 |
} |
236 | 242 |
|
243 |
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 |
|
|
237 | 280 |
TBSkewb.fillInQuats(quats,perm,twist); |
238 | 281 |
} |
239 | 282 |
|
... | ... | |
265 | 308 |
if( result4<0 ) return result4; |
266 | 309 |
|
267 | 310 |
computeCornerQuats(quats,corners,freePerm); |
311 |
|
|
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 |
|
|
268 | 316 |
TBSkewb.computeCornerTwists(twist,quats); |
269 | 317 |
|
270 | 318 |
int total = 0; |
271 |
for(int i=0; i<4; i++) total += twist[FREE[i]];
|
|
319 |
for(int i=0; i<8; i++) total += twist[i];
|
|
272 | 320 |
if( (total%3)!=0 ) return ERROR_CORNER_TWISTED; |
273 | 321 |
int totalTwist = twist[0]+ 3*(twist[1]+ 3*(twist[2]+ 3*(twist[3]+ 3*(twist[4]+ 3*(twist[5]+ 3*twist[6]))))); |
274 | 322 |
|
275 |
int locationOfFree0 = TBSkewb.computeLocation(0,quats[1]); |
|
323 |
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; |
|
276 | 326 |
|
277 |
return center_perm_num+ 360*(totalTwist + 2187*locationOfFree0);
|
|
327 |
return center_perm_num+ 360*(totalTwist + 2187*freeLoc[0]);
|
|
278 | 328 |
} |
279 | 329 |
|
280 | 330 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
358 | 408 |
{ |
359 | 409 |
switch(index) |
360 | 410 |
{ |
361 |
case ERROR_CORNER_135_MISSING: return cornerError(res,1,3,5); |
|
362 |
case ERROR_CORNER_134_MISSING: return cornerError(res,1,3,4); |
|
363 |
case ERROR_CORNER_125_MISSING: return cornerError(res,1,2,5); |
|
364 |
case ERROR_CORNER_124_MISSING: return cornerError(res,1,2,4); |
|
365 |
case ERROR_CORNER_035_MISSING: return cornerError(res,0,3,5); |
|
366 |
case ERROR_CORNER_034_MISSING: return cornerError(res,0,3,4); |
|
367 |
case ERROR_CORNER_025_MISSING: return cornerError(res,0,2,5); |
|
368 |
case ERROR_CORNER_024_MISSING: return cornerError(res,0,2,4); |
|
369 |
|
|
370 |
case ERROR_CENTER_0_MISSING : return centerError(res,0); |
|
371 |
case ERROR_CENTER_1_MISSING : return centerError(res,1); |
|
372 |
case ERROR_CENTER_2_MISSING : return centerError(res,2); |
|
373 |
case ERROR_CENTER_3_MISSING : return centerError(res,3); |
|
374 |
case ERROR_CENTER_4_MISSING : return centerError(res,4); |
|
375 |
case ERROR_CENTER_5_MISSING : return centerError(res,5); |
|
376 |
|
|
377 |
case ERROR_CORNERS_CANNOT : return res.getString(R.string.solver_generic_corners_cannot); |
|
378 |
case ERROR_CORNER_TWISTED : return res.getString(R.string.solver_generic_corner_twist); |
|
379 |
case ERROR_TWO_CENTERS : return res.getString(R.string.solver_generic_two_centers); |
|
380 |
case ERROR_TWO_CORNERS : return res.getString(R.string.solver_generic_two_corners); |
|
411 |
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); |
|
381 | 434 |
} |
382 | 435 |
|
383 | 436 |
return null; |
src/main/res/values-de/strings.xml | ||
---|---|---|
102 | 102 |
<string name="solver_generic_edge_mono">%1$s-%2$s Kante?</string> |
103 | 103 |
<string name="solver_generic_edge_twice">Zwei %1$s-%2$s Kanten!</string> |
104 | 104 |
<string name="solver_generic_edge_three">Es sollten 3 %1$s Kanten sein!</string> |
105 |
<string name="solver_generic_free_corners_odd">Freie Ecken bilden keine gerade Permutation!</string> |
|
106 |
<string name="solver_generic_free_corners_rotated">Freie Ecken falsch gedreht!</string> |
|
105 | 107 |
|
106 | 108 |
<string name="solver_cube3_error1">Es gibt nur %1$d %2$s Facelets.</string> |
107 | 109 |
<string name="solver_cube3_error2">Nicht alle 12 Kanten gibt es genau einmal!</string> |
src/main/res/values-es/strings.xml | ||
---|---|---|
102 | 102 |
<string name="solver_generic_edge_mono">Borde %1$s-%2$s?</string> |
103 | 103 |
<string name="solver_generic_edge_twice">¡Dos bordes %1$s-%2$s!</string> |
104 | 104 |
<string name="solver_generic_edge_three">¡Debe haber 3 bordes %1$s!</string> |
105 |
<string name="solver_generic_free_corners_odd">¡Las esquinas libres no forman una permutación uniforme!</string> |
|
106 |
<string name="solver_generic_free_corners_rotated">¡Esquinas libres giradas incorrectamente!</string> |
|
105 | 107 |
|
106 | 108 |
<string name="solver_cube3_error1">Solo hay %1$d facetas %2$s.</string> |
107 | 109 |
<string name="solver_cube3_error2">¡No todos los 12 bordes existen exactamente una vez!</string> |
src/main/res/values-fr/strings.xml | ||
---|---|---|
102 | 102 |
<string name="solver_generic_edge_mono">Bord %1$s-%2$s?</string> |
103 | 103 |
<string name="solver_generic_edge_twice">Deux bords %1$s-%2$s !</string> |
104 | 104 |
<string name="solver_generic_edge_three">Il devrait y avoir 3 bords %1$s !</string> |
105 |
<string name="solver_generic_free_corners_odd">Les coins libres ne forment pas une permutation égale !</string> |
|
106 |
<string name="solver_generic_free_corners_rotated">Coins libres mal tournés !</string> |
|
105 | 107 |
|
106 | 108 |
<string name="solver_cube3_error1">Il n\'y a que %1$d facettes %2$s.</string> |
107 | 109 |
<string name="solver_cube3_error2">Les 12 arêtes n\'existent pas exactement une fois !</string> |
src/main/res/values-ja/strings.xml | ||
---|---|---|
102 | 102 |
<string name="solver_generic_edge_mono">%1$s%2$s エッジ?</string> |
103 | 103 |
<string name="solver_generic_edge_twice">2 つの %1$s-%2$s エッジ!</string> |
104 | 104 |
<string name="solver_generic_edge_three">3 つの %1$s エッジがあるはずです!</string> |
105 |
<string name="solver_generic_free_corners_odd">フリーコーナーは均等な順列を形成しません。</string> |
|
106 |
<string name="solver_generic_free_corners_rotated">フリーコーナーが正しく回転していません!</string> |
|
105 | 107 |
|
106 | 108 |
<string name="solver_cube3_error1">%2$s小顔は%1$dつだけ</string> |
107 | 109 |
<string name="solver_cube3_error2">12 のエッジすべてが 存在するわけではありません。</string> |
src/main/res/values-ko/strings.xml | ||
---|---|---|
102 | 102 |
<string name="solver_generic_edge_mono">%1$s%2$s 에지?</string> |
103 | 103 |
<string name="solver_generic_edge_twice">두 개의 %1$s-%2$s 모서리!</string> |
104 | 104 |
<string name="solver_generic_edge_three">3개의 %1$s 모서리가 있어야 합니다!</string> |
105 |
<string name="solver_generic_free_corners_odd">자유로운 모서리는 균등한 순열을 형성하지 않습니다!</string> |
|
106 |
<string name="solver_generic_free_corners_rotated">자유 코너가 잘못 회전했습니다!</string> |
|
105 | 107 |
|
106 | 108 |
<string name="solver_cube3_error1">%2$s작은 얼굴은 %1$d개뿐입니다.</string> |
107 | 109 |
<string name="solver_cube3_error2">12개의 가장자리 모두가 정확하게 한 번 존재하지 않습니다!</string> |
src/main/res/values-pl/strings.xml | ||
---|---|---|
102 | 102 |
<string name="solver_generic_edge_mono">%1$s-%2$s krawędz?</string> |
103 | 103 |
<string name="solver_generic_edge_twice">Dwie krawędzie %1$s-%2$s!</string> |
104 | 104 |
<string name="solver_generic_edge_three">Powinny być 3 %1$s krawędzie!</string> |
105 |
<string name="solver_generic_free_corners_odd">Wolne rogi powinny być parzysto spermutowane!</string> |
|
106 |
<string name="solver_generic_free_corners_rotated">Wolne rogi są źle obrócone!</string> |
|
105 | 107 |
|
106 | 108 |
<string name="solver_cube3_error1">Jest tylko %1$d %2$s ścian.</string> |
107 | 109 |
<string name="solver_cube3_error2">Któraś z 12 krawędzi nie istnieje!</string> |
src/main/res/values-ru/strings.xml | ||
---|---|---|
102 | 102 |
<string name="solver_generic_edge_mono">%1$s-%2$s ребрo?</string> |
103 | 103 |
<string name="solver_generic_edge_twice">Два ребра %1$s-%2$s!</string> |
104 | 104 |
<string name="solver_generic_edge_three">Должно быть 3 %1$s ребра!</string> |
105 |
<string name="solver_generic_free_corners_odd">Свободные углы не образуют четную перестановку!</string> |
|
106 |
<string name="solver_generic_free_corners_rotated">Свободные углы неправильно повернуты!</string> |
|
105 | 107 |
|
106 | 108 |
<string name="solver_cube3_error1">Всего %1$d %2$s граней!</string> |
107 | 109 |
<string name="solver_cube3_error2">Не все 12 ребер существуют в единичном экземпляре!</string> |
src/main/res/values-zh-rCN/strings.xml | ||
---|---|---|
108 | 108 |
<string name="solver_generic_edge_mono">%1$s%2$s 边缘?</string> |
109 | 109 |
<string name="solver_generic_edge_twice">两个 %1$s-%2$s 边!</string> |
110 | 110 |
<string name="solver_generic_edge_three">应该有 3 %1$s 条边!</string> |
111 |
<string name="solver_generic_free_corners_odd">自由角不形成均匀排列!</string> |
|
112 |
<string name="solver_generic_free_corners_rotated">自由角旋转不正确!</string> |
|
111 | 113 |
|
112 | 114 |
<string name="solver_cube3_error1">只有%1$d个%2$s小面</string> |
113 | 115 |
<string name="solver_cube3_error2">并非所有12条边都只存在一次!</string> |
src/main/res/values-zh-rTW/strings.xml | ||
---|---|---|
102 | 102 |
<string name="solver_generic_edge_mono">%1$s%2$s 邊緣?</string> |
103 | 103 |
<string name="solver_generic_edge_twice">兩個 %1$s-%2$s 邊!</string> |
104 | 104 |
<string name="solver_generic_edge_three">應該有 3 %1$s 條邊!</string> |
105 |
<string name="solver_generic_free_corners_odd">自由角不形成均勻排列!</string> |
|
106 |
<string name="solver_generic_free_corners_rotated">自由角旋轉不正確!</string> |
|
105 | 107 |
|
106 | 108 |
<string name="solver_cube3_error1">只有%1$d個%2$s小臉</string> |
107 | 109 |
<string name="solver_cube3_error2">並非所有12條邊都只存在一次!</string> |
src/main/res/values/strings.xml | ||
---|---|---|
122 | 122 |
<string name="solver_generic_edge_mono">%1$s-%2$s edge?</string> |
123 | 123 |
<string name="solver_generic_edge_twice">Two %1$s-%2$s edges!</string> |
124 | 124 |
<string name="solver_generic_edge_three">There should be 3 %1$s edges!</string> |
125 |
<string name="solver_generic_free_corners_odd">Free corners do not form an even permutation!</string> |
|
126 |
<string name="solver_generic_free_corners_rotated">Free corners incorrectly rotated!</string> |
|
125 | 127 |
|
126 | 128 |
<string name="solver_cube3_error1">There are only %1$d %2$s facelets.</string> |
127 | 129 |
<string name="solver_cube3_error2">Not all 12 edges exist exactly once!</string> |
... | ... | |
131 | 133 |
<string name="solver_cube3_error8">Timeout, no solution found in 20 seconds!</string> |
132 | 134 |
<string name="solver_cube3_error9">Solver interrupted!</string> |
133 | 135 |
|
134 |
|
|
135 | 136 |
<string name="color_yellow1">yellow</string> |
136 | 137 |
<string name="color_white1">white</string> |
137 | 138 |
<string name="color_blue1">blue</string> |
Also available in: Unified diff
Fix SkewbSolver.